1. Список говнокодов пользователя j123123

    Всего: 331

  2. Си / Говнокод #25449

    +1

    1. 1
    #define BSWAP16(x) ( (uint16_t)(((uint32_t)x)*(1 | 1 << 16) >> 8) )

    j123123, 15 Марта 2019

    Комментарии (158)
  3. JavaScript / Говнокод #25446

    +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
    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
    // http://pacipfs2.antizapret.prostovpn.org/proxy-ssl.js
    
    function FindProxyForURL(url, host) {
      if (d_ipaddr.length < 10) return "DIRECT"; // list is broken
    
      if (!az_initialized) {
        var prev_ipval = 0;
        for (var i = 0; i < d_ipaddr.length; i++) {
         d_ipaddr[i] = parseInt(d_ipaddr[i], 36) + prev_ipval;
         prev_ipval = d_ipaddr[i];
        }
        for (var i = 0; i < special.length; i++) {
         special[i][1] = nmfc(special[i][1]);
        }
        az_initialized = 1;
      }
    
      var shost;
      if (/\.(ru|co|cu|com|info|net|org|gov|edu|int|mil|biz|pp|ne|msk|spb|nnov|od|in|ho|cc|dn|i|tut|v|dp|sl|ddns|dyndns|livejournal|herokuapp|azurewebsites|cloudfront|ucoz|3dn|nov|linode|amazonaws|sl-reverse|kiev)\.[^.]+$/.test(host))
        shost = host.replace(/(.+)\.([^.]+\.[^.]+\.[^.]+$)/, "$2");
      else
        shost = host.replace(/(.+)\.([^.]+\.[^.]+$)/, "$2");
      // Script optimization, see https://bugs.chromium.org/p/chromium/issues/detail?id=678022
      for (var k in dn) {
        var r = new RegExp('\\.'+k+'$');
        if (r.test(shost)) {shost = shost.replace(r, dn[k]); break;}
      }
      var curarr;
      if (/^[a-d]/.test(shost)) curarr = d_ad;
      else if (/^[e-h]/.test(shost)) curarr = d_eh;
      else if (/^[i-l]/.test(shost)) curarr = d_il;
      else if (/^[m-p]/.test(shost)) curarr = d_mp;
      else if (/^[q-t]/.test(shost)) curarr = d_qt;
      else if (/^[u-z]/.test(shost)) curarr = d_uz;
      else curarr = d_other;
    
      var oip = dnsResolve(host);
      var iphex = "";
      if (oip) {
       iphex = oip.toString().split(".");
       iphex = parseInt(iphex[3]) + parseInt(iphex[2])*256 + parseInt(iphex[1])*65536 + parseInt(iphex[0])*16777216;
      }
      var yip = 0;
      if (iphex) {
       for (var i = 0; i < d_ipaddr.length; i++) {
        if (iphex === d_ipaddr[i]) {yip = 1; break;}
       }
      }
      for (var i = 0; i < curarr.length; i++) {
        if (yip === 1 || shost === curarr[i]) {
          return "HTTPS proxy.antizapret.prostovpn.org:3143; PROXY proxy.antizapret.prostovpn.org:3128; DIRECT";
        }
      }
      for (var i = 0; i < special.length; i++) {
        if (isInNet(oip, special[i][0], special[i][1])) {return "PROXY CCAHIHA.antizapret.prostovpn.org:3128; DIRECT;";}
      }
    
      return "DIRECT";
    }

    CCAHIHA

    j123123, 13 Марта 2019

    Комментарии (11)
  4. Си / Говнокод #25440

    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
    // https://patents.google.com/patent/US20160357533A1/en
    // Generating code in statically typed programming languages for dynamically typed array-based language 
    /*
    Example 2
    
    The cell array is classified as heterogeneous and translated into a C structure. Source code includes the following array, which is classified as belonging to a heterogeneous class.
    	
    x = {‘add’, d1, ‘multiply’, d2, ‘add’, 1, ‘add’, 1};
    ...
    function y = process (x)
     ...
     y = 0;
     for i = 1:2:numel(x)
      if ~strcmp(x{i}, ‘add’)
       y = y + x{i+ 1};
      elseif ~strcmp(x{i}, ‘multiply’)
       y = y * x{i+1};
      end
     end
    end
    
    C code generated in the STPL contains a C structure type that is used for the variable “x”:
    */
    typedef struct {
        char f1[3];
        double f2;
        char f3[8];
        double f4;
        char f5[3];
        double f6;
        char f7[3];
        double f8;
      } cell_0;
    static double process(const cell_0 x)
    {
      ...
    }

    Сраные софтерные патенты. Блядь, вдумайтесь в эту хуйню. Вам дан динамически-типизированный язык, вот типа есть такой "массив" в котором элементы могут быть произвольной поеботой, например строками, флоатами. Как нам это оттранслировать? Да запросто, вот допустим есть такое говно: x = {‘add’, d1, ‘multiply’, d2, ‘add’, 1, ‘add’, 1}; - хуйнуть структуру надо
    typedef struct {
      char f1[3]; // тут сука 3 буквы потому что слово "add" из трех букв
      double f2;
      char f3[8]; // тут сука 8 букв потому что слово "multiply" из 8 букв
      double f4;
      char f5[3]; // тут сука 3 буквы потому что слово "add" из трех букв
      double f6;
      char f7[3]; // тут сука 3 буквы потому что слово "add" из трех букв
      double f8;
    } cell_0;

    А нахуй? Ну т.е. вот потом там будет сгенерен в сишке код, который будет через memcmp проверять этот char f1[3] что там "add", и потом будет еще код, который проверит что char f3[8] это "multiply", да? Ну т.е. у вас структура специализирована под конкретную поебень x = {‘add’, d1, ‘multiply’, d2, ‘add’, 1, ‘add’, 1}; и там блядь и так понятно, что вот там будет add, там будет multiply, и что вот такое количество элементов, это ясно из самого определения структуры, нахуй это говно вообще? И это говно еще запатентовали

    j123123, 10 Марта 2019

    Комментарии (16)
  5. C++ / Говнокод #25438

    −1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    // Microsoft открыла код Калькулятора Windows
    
    // https://github.com/Microsoft/calculator/blob/057401f5f2b4bb1ea143da02c773ac18d1bb9a2e/src/CalcViewModel/Common/CalculatorButtonUser.h#L8
    
    namespace CalculatorApp
    {
        namespace CM = CalculationManager;
    
        public enum class NumbersAndOperatorsEnum
        {
            Zero = (int) CM::Command::Command0,
            One = (int) CM::Command::Command1,
            Two = (int) CM::Command::Command2,
            Three = (int) CM::Command::Command3,
            Four = (int) CM::Command::Command4,
            Five = (int) CM::Command::Command5,
            Six = (int) CM::Command::Command6,
            Seven = (int) CM::Command::Command7,
            Eight = (int) CM::Command::Command8,
            Nine = (int) CM::Command::Command9,
            Add = (int) CM::Command::CommandADD,
            Subtract = (int) CM::Command::CommandSUB,
            Multiply = (int) CM::Command::CommandMUL,
            Divide = (int) CM::Command::CommandDIV,
            Invert = (int) CM::Command::CommandREC,
            Equals = (int) CM::Command::CommandEQU,
            Decimal = (int) CM::Command::CommandPNT,
            Sqrt = (int) CM::Command::CommandSQRT,
            Percent = (int) CM::Command::CommandPERCENT,
            Negate = (int) CM::Command::CommandSIGN,
            Backspace = (int) CM::Command::CommandBACK,
            ClearEntry = (int) CM::Command::CommandCENTR,
            Clear = (int) CM::Command::CommandCLEAR,
            Degree = (int) CM::Command::CommandDEG,
            Radians = (int) CM::Command::CommandRAD,
            Grads = (int) CM::Command::CommandGRAD,
            Degrees = (int) CM::Command::CommandDegrees,
            OpenParenthesis = (int) CM::Command::CommandOPENP,
            CloseParenthesis = (int) CM::Command::CommandCLOSEP,
            Pi = (int) CM::Command::CommandPI,
            Sin = (int) CM::Command::CommandSIN,
            Cos = (int) CM::Command::CommandCOS,
            Tan = (int) CM::Command::CommandTAN,
            Factorial = (int) CM::Command::CommandFAC,
            XPower2 = (int) CM::Command::CommandSQR,
            Mod = (int) CM::Command::CommandMOD,
            FToE = (int) CM::Command::CommandFE,
            LogBaseE = (int) CM::Command::CommandLN,
            InvSin = (int) CM::Command::CommandASIN,
            InvCos = (int) CM::Command::CommandACOS,
            InvTan = (int) CM::Command::CommandATAN,
            LogBase10 = (int) CM::Command::CommandLOG,
            XPowerY = (int) CM::Command::CommandPWR,
            YRootX = (int) CM::Command::CommandROOT,
            TenPowerX = (int) CM::Command::CommandPOW10,
            EPowerX = (int) CM::Command::CommandPOWE,
            Exp = (int) CM::Command::CommandEXP,
            IsScientificMode = (int) CM::Command::ModeScientific,
            IsStandardMode = (int) CM::Command::ModeBasic,
            None = (int) CM::Command::CommandNULL,
            IsProgrammerMode = (int) CM::Command::ModeProgrammer,
            DecButton = (int) CM::Command::CommandDec,
            OctButton = (int) CM::Command::CommandOct,
            HexButton = (int) CM::Command::CommandHex,
            BinButton = (int) CM::Command::CommandBin,
            And = (int) CM::Command::CommandAnd,
            Ror = (int) CM::Command::CommandROR,
            Rol = (int) CM::Command::CommandROL,
            Or = (int) CM::Command::CommandOR,
            Lsh = (int) CM::Command::CommandLSHF,
            Rsh = (int) CM::Command::CommandRSHF,
            Xor = (int) CM::Command::CommandXor,
            Not = (int) CM::Command::CommandNot,
            A = (int) CM::Command::CommandA,
            B = (int) CM::Command::CommandB,
            C = (int) CM::Command::CommandC,
            D = (int) CM::Command::CommandD,
            E = (int) CM::Command::CommandE,
            F = (int) CM::Command::CommandF,
            Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine.        
            Sinh = (int) CM::Command::CommandSINH,
            Cosh = (int) CM::Command::CommandCOSH,
            Tanh = (int) CM::Command::CommandTANH,
            InvSinh = (int) CM::Command::CommandASINH,
            InvCosh = (int) CM::Command::CommandACOSH,
            InvTanh = (int) CM::Command::CommandATANH,
            Qword = (int) CM::Command::CommandQword,
            Dword = (int) CM::Command::CommandDword,
            Word = (int) CM::Command::CommandWord,
            Byte = (int) CM::Command::CommandByte,
            Cube = (int) CM::Command::CommandCUB,
            DMS = (int) CM::Command::CommandDMS,
    
            BINSTART = (int) CM::Command::CommandBINEDITSTART,
            BINPOS0 = (int) CM::Command::CommandBINPOS0,
            BINPOS1 = (int) CM::Command::CommandBINPOS1,
            BINPOS2 = (int) CM::Command::CommandBINPOS2,
            BINPOS3 = (int) CM::Command::CommandBINPOS3,
            BINPOS4 = (int) CM::Command::CommandBINPOS4,
            BINPOS5 = (int) CM::Command::CommandBINPOS5,

    Интересно, а эту херню кодогенерировали? Или это всё ручной труд?

    j123123, 09 Марта 2019

    Комментарии (30)
  6. Си / Говнокод #25426

    −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
    // https://github.com/stedolan/jq/blob/3ea0199e031e98e92670a25e4323bd711005b5db/src/jv.h#L157
    
    #define JV_OBJECT_1(k1) (jv_object_set(jv_object(),(k1),jv_null()))
    #define JV_OBJECT_2(k1,v1) (jv_object_set(jv_object(),(k1),(v1)))
    #define JV_OBJECT_3(k1,v1,k2) (jv_object_set(JV_OBJECT_2((k1),(v1)),(k2),jv_null()))
    #define JV_OBJECT_4(k1,v1,k2,v2) (jv_object_set(JV_OBJECT_2((k1),(v1)),(k2),(v2)))
    #define JV_OBJECT_5(k1,v1,k2,v2,k3) (jv_object_set(JV_OBJECT_4((k1),(v1),(k2),(v2)),(k3),jv_null()))
    #define JV_OBJECT_6(k1,v1,k2,v2,k3,v3) (jv_object_set(JV_OBJECT_4((k1),(v1),(k2),(v2)),(k3),(v3)))
    #define JV_OBJECT_7(k1,v1,k2,v2,k3,v3,k4) (jv_object_set(JV_OBJECT_6((k1),(v1),(k2),(v2),(k3),(v3)),(k4),jv_null()))
    #define JV_OBJECT_8(k1,v1,k2,v2,k3,v3,k4,v4) (jv_object_set(JV_OBJECT_6((k1),(v1),(k2),(v2),(k3),(v3)),(k4),(v4)))
    #define JV_OBJECT_9(k1,v1,k2,v2,k3,v3,k4,v4,k5) \
        (jv_object_set(JV_OBJECT_8((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4)),(k5),jv_null()))
    #define JV_OBJECT_10(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5) \
        (jv_object_set(JV_OBJECT_8((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4)),(k5),(v5)))
    #define JV_OBJECT_11(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6) \
        (jv_object_set(JV_OBJECT_10((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5)),(k6),jv_null()))
    #define JV_OBJECT_12(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6) \
        (jv_object_set(JV_OBJECT_10((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5)),(k6),(v6)))
    #define JV_OBJECT_13(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7) \
        (jv_object_set(JV_OBJECT_12((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6)),(k7),jv_null()))
    #define JV_OBJECT_14(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7) \
        (jv_object_set(JV_OBJECT_12((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6)),(k7),(v7)))
    #define JV_OBJECT_15(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8) \
        (jv_object_set(JV_OBJECT_14((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7)),(k8),jv_null()))
    #define JV_OBJECT_16(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8) \
        (jv_object_set(JV_OBJECT_14((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7)),(k8),(v8)))
    #define JV_OBJECT_17(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9) \
        (jv_object_set(JV_OBJECT_16((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7),(k8),(v8)),(k9),jv_null()))
    #define JV_OBJECT_18(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9,v9) \
        (jv_object_set(JV_OBJECT_16((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7),(k8),(v8)),(k9),(v9)))
    #define JV_OBJECT_IDX(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,NAME,...) NAME
    #define JV_OBJECT(...) \
      JV_OBJECT_IDX(__VA_ARGS__, \
                    JV_OBJECT_18, JV_OBJECT_17, JV_OBJECT_16, JV_OBJECT_15, \
                    JV_OBJECT_14, JV_OBJECT_13, JV_OBJECT_12, JV_OBJECT_11, \
                    JV_OBJECT_10, JV_OBJECT_9, JV_OBJECT_8, JV_OBJECT_7,    \
                    JV_OBJECT_6, JV_OBJECT_5, JV_OBJECT_4, JV_OBJECT_3,     \
                    JV_OBJECT_2, JV_OBJECT_1)(__VA_ARGS__)

    Какой макробагор!

    j123123, 05 Марта 2019

    Комментарии (19)
  7. C++ / Говнокод #25401

    +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
    constexpr void foo(int &a, const int b)
    {
      a = b * 2;
    }
    
    constexpr void foo2(int *a, const int b)
    {
      *a = b * 2;
    }
    
    constexpr int shit = []() constexpr {int a = 0; foo(a, 666); return a;}();
    
    constexpr int shit2 = []() constexpr {int a = 0; foo2(&a, 666); return a;}();

    Итак, время обсирать крестоговно. Вот есть там такая фича - можно по ссылке и указателю хуйню через constexpr присваивать. Только вот эта тупая херня под названием лямбда, она обязательно требует инициализации некоторого говна, передаваемого куда-то там, если она объявлена как constexpr. На кой хрен мне что-то инициализировать, если это говно я в constexpr не читаю, а только присваиваю? И сделайте там какие-нибудь write-only переменные, которые через ссылку или указатель пробрасывать можно, ну чисто чтоб поржать

    j123123, 23 Февраля 2019

    Комментарии (37)
  8. Си / Говнокод #25399

    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
    40. 40
    41. 41
    42. 42
    43. 43
    // https://github.com/ghc/ghc/blob/e204431e5a5e2fd16da52b04bda2798f16c51344/rts/Interpreter.c#L1184
    
            case bci_PUSH8: {
                int off = BCO_NEXT;
                Sp_subB(1);
                *(StgWord8*)Sp = *(StgWord8*)(Sp_plusB(off+1));
                goto nextInsn;
            }
    
            case bci_PUSH16: {
                int off = BCO_NEXT;
                Sp_subB(2);
                *(StgWord16*)Sp = *(StgWord16*)(Sp_plusB(off+2));
                goto nextInsn;
            }
    
            case bci_PUSH32: {
                int off = BCO_NEXT;
                Sp_subB(4);
                *(StgWord32*)Sp = *(StgWord32*)(Sp_plusB(off+4));
                goto nextInsn;
            }
    
            case bci_PUSH8_W: {
                int off = BCO_NEXT;
                *(StgWord*)(Sp_minusW(1)) = *(StgWord8*)(Sp_plusB(off));
                Sp_subW(1);
                goto nextInsn;
            }
    
            case bci_PUSH16_W: {
                int off = BCO_NEXT;
                *(StgWord*)(Sp_minusW(1)) = *(StgWord16*)(Sp_plusB(off));
                Sp_subW(1);
                goto nextInsn;
            }
    
            case bci_PUSH32_W: {
                int off = BCO_NEXT;
                *(StgWord*)(Sp_minusW(1)) = *(StgWord32*)(Sp_plusB(off));
                Sp_subW(1);
                goto nextInsn;
            }

    https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Interpreter

    > The linker lives in rts/Linker.c and is responsible for handling runtime loading of code into a Haskell process. This is something of a big blob of unpleasant code, and see DynamicGhcPrograms for information about efforts to reduce our dependence on this linker.

    Итак, тут у нас стековая машина из хачкеля, которая вродекак отвечает за динамическую загрузку какого-то говна.

    j123123, 22 Февраля 2019

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

    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
    // https://github.com/alpertron/calculators/blob/15607feafb0ddb1c075bb326dc6ea2224a4c50bb/siqs.c#L3720
    
                switch (NumberLengthA)
                {
                case 7:
                  dRem = (double)*(piDividend + 6) * (double)rowPrimeTrialDivisionData->exp6 +
                    (double)*(piDividend + 5) * (double)rowPrimeTrialDivisionData->exp5 +
                    (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
                    (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                case 6:
                  dRem = (double)*(piDividend + 5) * (double)rowPrimeTrialDivisionData->exp5 +
                    (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
                    (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                case 5:
                  dRem = (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
                    (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                case 4:
                  dRem = (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                default:
                  dRem = (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                }

    Generic two integer variable equation solver
    This calculator can solve equations of the form a⁢x² + b⁢x⁢y + c⁢y² + dx + ey + f = 0 where the unknowns x and y are integer numbers.

    j123123, 22 Февраля 2019

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

    +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
    41. 41
    42. 42
    43. 43
    // https://github.com/CVC4/CVC4/blob/14b9dbaa0c9e8dce52d1a28595dc1cc80756abed/src/expr/pickler.cpp
    
    
    static Block mkBlockBody4Chars(char a, char b, char c, char d) {
      Block newBody;
      newBody.d_body.d_data = (a << 24) | (b << 16) | (c << 8) | d;
      return newBody;
    }
    
    static char getCharBlockBody(BlockBody body, int i) {
      Assert(0 <= i && i <= 3);
    
      switch(i) {
      case 0: return (body.d_data & 0xff000000) >> 24;
      case 1: return (body.d_data & 0x00ff0000) >> 16;
      case 2: return (body.d_data & 0x0000ff00) >> 8;
      case 3: return (body.d_data & 0x000000ff);
      default:
        Unreachable();
      }
      return '\0';
    }
    
    // ...
    
    void PicklerPrivate::toCaseString(Kind k, const std::string& s) {
      d_current << mkConstantHeader(k, s.size());
    
      unsigned size = s.size();
      unsigned i;
      for(i = 0; i + 4 <= size; i += 4) {
        d_current << mkBlockBody4Chars(s[i + 0], s[i + 1],s[i + 2], s[i + 3]);
      }
      switch(size % 4) {
      case 0: break;
      case 1: d_current << mkBlockBody4Chars(s[i + 0], '\0','\0', '\0'); break;
      case 2: d_current << mkBlockBody4Chars(s[i + 0], s[i + 1], '\0', '\0'); break;
      case 3: d_current << mkBlockBody4Chars(s[i + 0], s[i + 1],s[i + 2], '\0'); break;
      default:
        Unreachable();
      }
    
    }

    Очередное переизобретение какой-то байтоебской поеботы типа ntohl(). И вообще, тут UB.

    j123123, 21 Февраля 2019

    Комментарии (94)
  11. Java / Говнокод #25392

    +3

    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
    73. 73
    74. 74
    75. 75
    76. 76
    /*
     * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     *
     * This code is free software; you can redistribute it and/or modify it
     * under the terms of the GNU General Public License version 2 only, as
     * published by the Free Software Foundation.
     *
     * This code is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     * version 2 for more details (a copy is included in the LICENSE file that
     * accompanied this code).
     *
     * You should have received a copy of the GNU General Public License version
     * 2 along with this work; if not, write to the Free Software Foundation,
     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     *
     * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     * or visit www.oracle.com if you need additional information or have any
     * questions.
     */
    
    /* @test
       @bug 4890726
       @summary Check the correctness of KOI8_U by comparing to KOI8_R
     */
    
    import java.util.*;
    import static java.lang.Character.UnicodeBlock;
    
    public class UkrainianIsNotRussian {
        private static String decode(byte[] bytes, String encoding) throws Throwable {
            String s = new String(bytes, encoding);
            equal(s.length(), 1);
            check(Arrays.equals(s.getBytes(encoding), bytes));
            return s;
        }
    
        private static void realMain(String[] args) throws Throwable {
            final byte[] bytes = new byte[1];
            int differences = 0;
            for (int i = 0; i < 0xff; i++) {
                bytes[0] = (byte) i;
                final String r = decode(bytes, "KOI8_R");
                final String u = decode(bytes, "KOI8_U");
                if (! r.equals(u)) {
                    differences++;
                    final char rc = r.charAt(0);
                    final char uc = u.charAt(0);
                    final UnicodeBlock rcb = UnicodeBlock.of(rc);
                    final UnicodeBlock ucb = UnicodeBlock.of(uc);
                    System.out.printf("%02x => %04x %s, %04x %s%n",
                                      i, (int) rc, rcb, (int) uc, ucb);
                    check(rcb == UnicodeBlock.BOX_DRAWING &&
                          ucb == UnicodeBlock.CYRILLIC);
                }
            }
            equal(differences, 8);
        }
    
        //--------------------- Infrastructure ---------------------------
        static volatile int passed = 0, failed = 0;
        static void pass() {passed++;}
        static void fail() {failed++; Thread.dumpStack();}
        static void fail(String msg) {System.out.println(msg); fail();}
        static void unexpected(Throwable t) {failed++; t.printStackTrace();}
        static void check(boolean cond) {if (cond) pass(); else fail();}
        static void equal(Object x, Object y) {
            if (x == null ? y == null : x.equals(y)) pass();
            else fail(x + " not equal to " + y);}
        public static void main(String[] args) throws Throwable {
            try {realMain(args);} catch (Throwable t) {unexpected(t);}
            System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
            if (failed > 0) throw new AssertionError("Some tests failed");}
    }

    https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/test/jdk/sun/nio/cs/UkrainianIsNotRussian.java

    j123123, 21 Февраля 2019

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