1. Си / Говнокод #27294

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    // https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Common-Function-Attributes.html
    
    access
    access (access-mode, ref-index)
    access (access-mode, ref-index, size-index)
    
    // примеры:
    
    __attribute__ ((access (read_only, 1))) int puts (const char*);
    __attribute__ ((access (read_only, 1, 2))) void* memcpy (void*, const void*, size_t);
    
    __attribute__ ((access (read_write, 1), access (read_only, 2))) char* strcat (char*, const char*);
    
    __attribute__ ((access (write_only, 1), access (read_only, 2))) char* strcpy (char*, const char*);
    __attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (char*, int, FILE*);

    В GCC 10 какой-то новый атрибут access появился, чтоб более строго что-то там гарантировать:

    The access attribute enables the detection of invalid or unsafe accesses by functions to which they apply or their callers, as well as write-only accesses to objects that are never read from. Such accesses may be diagnosed by warnings such as -Wstringop-overflow, -Wuninitialized, -Wunused, and others.

    The access attribute specifies that a function to whose by-reference arguments the attribute applies accesses the referenced object according to access-mode. The access-mode argument is required and must be one of three names: read_only, read_write, or write_only. The remaining two are positional arguments.

    The required ref-index positional argument denotes a function argument of pointer (or in C++, reference) type that is subject to the access. The same pointer argument can be referenced by at most one distinct access attribute.

    The optional size-index positional argument denotes a function argument of integer type that specifies the maximum size of the access. The size is the number of elements of the type referenced by ref-index, or the number of bytes when the pointer type is void*. When no size-index argument is specified, the pointer argument must be either null or point to a space that is suitably aligned and large for at least one object of the referenced type (this implies that a past-the-end pointer is not a valid argument). The actual size of the access may be less but it must not be more.

    j123123, 14 Марта 2021

    Комментарии (242)
  2. Куча / Говнокод #27293

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    start_link(Shard, Subscriber) ->
        gen_server:start_link(?MODULE, {server, Shard, Subscriber}, []).
    
    start_link_client(Shard, RemoteNode, Parent) ->
        gen_server:start_link(?MODULE, {client, Shard, RemoteNode, Parent}, []).
    
    
    init({server, Shard, Subscriber}) ->
        {ok, #server{ shard      = Shard
                    , subscriber = Subscriber
                    }};
    init({client, Shard, RemoteNode, Parent}) ->
        {ok, #client{ parent     = Parent
                    , shard      = Shard
                    }}.

    CHayT, 12 Марта 2021

    Комментарии (12)
  3. Си / Говнокод #27292

    +2

    1. 1
    2. 2
    3. 3
    unsigned three = 1;
    unsigned five = 5;
    unsigned seven = 7;

    https://github.com/torvalds/linux/blob/d158fc7f36a25e19791d25a55da5623399a2644f/fs/ext4/resize.c#L698

    MAKAKA, 12 Марта 2021

    Комментарии (210)
  4. 1C / Говнокод #27291

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    // Раздел 1 продолжение, расчет графы 5 и 6.
    	Области.П010000105.Значение = Области.П010000205.Значение
    	                                         + Области.П010000305.Значение
    	                                         + Области.П010000405.Значение
    	                                         + Области.П010000505.Значение
    	                                         + Области.П010000605.Значение
    	                                         + Области.П010000705.Значение
    	                                         + Области.П010000805.Значение
    	                                         + Области.П010000905.Значение
    	                                         + Области.П010001005.Значение
    	                                         + Области.П010001105.Значение;
    	Если Области.П010000105.Значение = 0 Тогда
    		ФорматПредставленияНуля = ?(ПустаяСтрока(Области.П010000205.Текст
    	                                           + Области.П010000305.Текст
    	                                           + Области.П010000405.Текст
    	                                           + Области.П010000505.Текст
    	                                           + Области.П010000605.Текст
    	                                           + Области.П010000705.Текст
    	                                           + Области.П010000805.Текст
    	                                           + Области.П010000905.Текст
    	                                           + Области.П010001005.Текст
    	                                           + Области.П010001105.Текст), "ЧН=' '", "ЧН=");
    		Области.П010000105.Формат = РегламентированнаяОтчетностьКлиентСервер.ЗаменитьПредставлениеНуляВСтрокеФормата(Области.П010000105.Формат, ФорматПредставленияНуля);
    	КонецЕсли;
    	
    	Области.П010000106.Значение = Области.П010000206.Значение
    	                                         + Области.П010000306.Значение
    	                                         + Области.П010000406.Значение
    	                                         + Области.П010000506.Значение
    	                                         + Области.П010000606.Значение
    	                                         + Области.П010000706.Значение
    	                                         + Области.П010000806.Значение
    	                                         + Области.П010000906.Значение
    	                                         + Области.П010001006.Значение
    	                                         + Области.П010001106.Значение;
    	Если Области.П010000106.Значение = 0 Тогда
    		ФорматПредставленияНуля = ?(ПустаяСтрока(Области.П010000206.Текст
    	                                           + Области.П010000306.Текст
    	                                           + Области.П010000406.Текст
    	                                           + Области.П010000506.Текст
    	                                           + Области.П010000606.Текст
    	                                           + Области.П010000706.Текст
    	                                           + Области.П010000806.Текст
    	                                           + Области.П010000906.Текст
    	                                           + Области.П010001006.Текст
    	                                           + Области.П010001106.Текст), "ЧН=' '", "ЧН=");
    		Области.П010000106.Формат = РегламентированнаяОтчетностьКлиентСервер.ЗаменитьПредставлениеНуляВСтрокеФормата(Области.П010000106.Формат, ФорматПредставленияНуля);
    	КонецЕсли;
    	
    	Области.П010000107.Значение = Области.П010000207.Значение
    	                                         + Области.П010000307.Значение
    	                                         + Области.П010000407.Значение
    	                                         + Области.П010000507.Значение
    	                                         + Области.П010000607.Значение
    	                                         + Области.П010000707.Значение
    	                                         + Области.П010000807.Значение
    	                                         + Области.П010000907.Значение
    	                                         + Области.П010001007.Значение
    	                                         + Области.П010001107.Значение;
    	Если Области.П010000107.Значение = 0 Тогда
    		ФорматПредставленияНуля = ?(ПустаяСтрока(Области.П010000207.Текст
    	                                           + Области.П010000307.Текст
    	                                           + Области.П010000407.Текст
    	                                           + Области.П010000507.Текст
    	                                           + Области.П010000607.Текст
    	                                           + Области.П010000707.Текст
    	                                           + Области.П010000807.Текст
    	                                           + Области.П010000907.Текст
    	                                           + Области.П010001007.Текст
    	                                           + Области.П010001107.Текст), "ЧН=' '", "ЧН=");
    		Области.П010000107.Формат = РегламентированнаяОтчетностьКлиентСервер.ЗаменитьПредставлениеНуляВСтрокеФормата(Области.П010000107.Формат, ФорматПредставленияНуля);
    	КонецЕсли;

    zoebis

    TOPT, 11 Марта 2021

    Комментарии (35)
  5. Python / Говнокод #27290

    0

    1. 1
    2. 2
    def IsZIPFile(filename):
        return filename.lower().endswith('.zip')

    ибааааать!

    Petro-san, 10 Марта 2021

    Комментарии (106)
  6. C++ / Говнокод #27289

    0

    1. 1
    Как крестьяне говна поели

    This function is defined as the RtlSecureZeroMemory function (see WinBase.h). The implementation of RtlSecureZeroMemory is provided inline and can be used on any version of Windows (see WinNT.h.)

    Use this function instead of ZeroMemory when you want to ensure that your data will be overwritten promptly, as some C++ compilers can optimize a call to ZeroMemory by removing it entirely.

    Petro-san, 10 Марта 2021

    Комментарии (80)
  7. JavaScript / Говнокод #27288

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    function main() {
        print("Hello", 1, false, true, parseInt("01"), parseFloat("00.1"));
    }
    
    // ASM
    ; ModuleID = 'LLVMDialectModule'
    source_filename = "LLVMDialectModule"
    target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
    target triple = "x86_64-pc-windows-msvc"
    
    @__true__ = internal constant [5 x i8] c"true\00"
    @__false__ = internal constant [6 x i8] c"false\00"
    @frmt_9481649210695450612 = internal constant [19 x i8] c"%s %d %s %s %d %f\0A\00"
    @s_3144841719139014728 = internal constant [5 x i8] c"00.1\00"
    @s_12300967985959445949 = internal constant [3 x i8] c"01\00"
    @s_1772061916968062023 = internal constant [6 x i8] c"Hello\00"
    
    declare i8* @malloc(i64)
    
    declare void @free(i8*)
    
    declare i32 @printf(i8*, ...)
    
    declare float @atof(i8*)
    
    declare i32 @atoi(i8*)
    
    define void @main() !dbg !3 {
      %1 = call i32 @atoi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @s_12300967985959445949, i64 0, i64 0)), !dbg !7
      %2 = call float @atof(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @s_3144841719139014728, i64 0, i64 0)), !dbg !9
      %3 = fpext float %2 to double, !dbg !10
      %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @frmt_9481649210695450612, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @s_1772061916968062023, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__false__, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__true__, i64 0, i64 0), i32 %1, double %3), !dbg !10
      br label %5, !dbg !11
    
    5:                                                ; preds = %0
      ret void, !dbg !11
    }
    
    !llvm.dbg.cu = !{!0}
    !llvm.module.flags = !{!2}

    Продолжение писания уе..(зачеркнуто) супер компилятора с TypeScript (JavaScript) в нативный код.

    как обычно компилим просто

    set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc 15\VC\lib
    set SDKPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc 15\SDK\lib
    tsc.exe --emit=llvm C:\temp\1.ts 2>1.ll
    llc.exe --filetype=obj -o=out.o 1.ll
    lld.exe -flavor link out.o "%LIBPATH%\libcmt.lib" "%LIBPATH%\libvcruntime.lib" "%SDKPATH%\kernel32.lib" "%SDKPATH%\libucrt.lib" "%SDKPATH%\uuid.lib"

    получаетм Ехе и грузим его. и результат

    =====================================
    и выполнение

    C:\>out.exe
    Hello 1 false true 1 0.100000

    ASD_77, 09 Марта 2021

    Комментарии (33)
  8. Куча / Говнокод #27287

    −5

    1. 1
    С праздником, девочки! ʕ ᵔᴥᵔ ʔ

    moderat0r, 08 Марта 2021

    Комментарии (96)
  9. Си / Говнокод #27285

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    #include <stdio.h>
    #include <string.h>
    
    double emit_fmadd(double a, double b, double c) __attribute ((noinline));
    
    double emit_fmadd(double a, double b, double c)
    {
      return a*b+c;
    }
    
    
    int main(void)
    {
      double a = 10.0000;
      double b = 1.00001;
      double c = 1.001;
      double res = emit_fmadd(a,b,c);
      unsigned char arr[sizeof(res)];
      memcpy(arr, &res, sizeof(res));
      for (int i = 0; i < sizeof(res); i++)
      {
        printf("%.2x ", arr[i]);
      }
      printf("\n");
    }
    
    /*
    gcc -O3 -march=skylake
    emit_fmadd:
            vfmadd132sd     xmm0, xmm2, xmm1
            ret
    
    
    gcc -O3 -march=x86-64
    emit_fmadd:
            mulsd   xmm0, xmm1
            addsd   xmm0, xmm2
            ret
    */

    Вот к чему плавучий питух приводит!
    https://godbolt.org/z/sP19zP

    j123123, 06 Марта 2021

    Комментарии (11)
  10. Куча / Говнокод #27284

    0

    1. 1
    IT Оффтоп #82

    #52: https://govnokod.ru/26817 https://govnokod.xyz/_26817
    #53: https://govnokod.ru/26833 https://govnokod.xyz/_26833
    #54: https://govnokod.ru/26840 https://govnokod.xyz/_26840
    #55: https://govnokod.ru/26844 https://govnokod.xyz/_26844
    #56: https://govnokod.ru/26862 https://govnokod.xyz/_26862
    #57: https://govnokod.ru/26890 https://govnokod.xyz/_26890
    #58: https://govnokod.ru/26916 https://govnokod.xyz/_26916
    #59: https://govnokod.ru/26934 https://govnokod.xyz/_26934
    #60: https://govnokod.ru/26949 https://govnokod.xyz/_26949
    #61: https://govnokod.ru/26980 https://govnokod.xyz/_26980
    #62: https://govnokod.ru/26999 https://govnokod.xyz/_26999
    #63: https://govnokod.ru/27004 https://govnokod.xyz/_27004
    #64: https://govnokod.ru/27020 https://govnokod.xyz/_27020
    #65: https://govnokod.ru/27027 https://govnokod.xyz/_27027
    #66: https://govnokod.ru/27040 https://govnokod.xyz/_27040
    #67: https://govnokod.ru/27049 https://govnokod.xyz/_27049
    #68: https://govnokod.ru/27061 https://govnokod.xyz/_27061
    #69: https://govnokod.ru/27071 https://govnokod.xyz/_27071
    #70: https://govnokod.ru/27097 https://govnokod.xyz/_27097
    #71: https://govnokod.ru/27115 https://govnokod.xyz/_27115
    #72: https://govnokod.ru/27120 https://govnokod.xyz/_27120
    #73: https://govnokod.ru/27136 https://govnokod.xyz/_27136
    #74: https://govnokod.ru/27160 https://govnokod.xyz/_27160
    #75: https://govnokod.ru/27166 https://govnokod.xyz/_27166
    #76: https://govnokod.ru/27168 https://govnokod.xyz/_27168
    #77: https://govnokod.ru/27186 https://govnokod.xyz/_27186
    #78: https://govnokod.ru/27219 https://govnokod.xyz/_27219
    #79: https://govnokod.ru/27254 https://govnokod.xyz/_27254
    #80: https://govnokod.ru/27270 https://govnokod.xyz/_27270
    #81: https://govnokod.ru/27280 https://govnokod.xyz/_27280

    nepeKamHblu_nemyx, 06 Марта 2021

    Комментарии (2019)