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

    Всего: 331

  2. Си / Говнокод #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)
  3. Куча / Говнокод #27276

    +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
    (set-logic UF)
    ; https://smtlib.cs.uiowa.edu/logics.shtml
    ; UF for the extension allowing free sort and function symbols 
    
    (set-option :produce-proofs true)
    
    (declare-sort M_list)
    
    (declare-fun m_node (M_list M_list) M_list)
    
    ; один хер какой порядок, можно переписать (a, b) на (b, a)
    (assert
      (forall ( (a M_list) (b M_list) )
        (=
          (m_node a b)
          (m_node b a)
        )
      )
    )
    
    ; если есть (a (b c)) то можно переписать на (с (a b))
    (assert
      (forall ( (a M_list) (b M_list) (c M_list) )
        (=
          (m_node a (m_node b c) )
          (m_node c (m_node a b) )
        )
      )
    )
    
    ; Можно создавать или удалять повторы, (a a) <=> a
    (assert
      (forall ( (a M_list))
        (=
          (m_node a a)
          a
        )
      )
    )
    
    
    ; Чтоб узнать, выводима ли такая-то хернь
    (declare-fun m_node_select (M_list M_list) Bool)
    
    
    (assert
      (forall ( (a M_list) (b M_list) )
        (m_node_select
          a (m_node a b)
        )
      )
    )
    
    ; проверяем, можно ли сконструировать (a a) из (c ((b d) a))
    (assert
      (not (forall ( (a M_list) (b M_list) (c M_list) (d M_list) )
        (m_node_select
          (m_node a a)
          (m_node c (m_node (m_node b d) a) )
        )
      ))
    )
    
    
    (check-sat)
    (get-proof)

    Вот вам немного гомоикон SMT-солвера. Эта вот хренотень сама доказывает, не то что какой-то там Coq.

    Понятно что по тем вот говноправилам можно чтоб всплыло 'a' и потом его удвоить "(a a) <=> a"
    потом через m_node_select вытащить этот дубликат

    j123123, 01 Марта 2021

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

    +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
    // https://deadlockempire.github.io/
    // Игра, где надо играть за планировщик чтоб вызвать дедлок
    
    // https://deadlockempire.github.io/#2-flags
    
    // First Army
    
    while (true) {
      while (flag != false) {
        ;
      }
      flag = true;
      critical_section();
      flag = false;
    }
    
    // Second Army
    
    while (true) {
      while (flag != false) {
        ;
      }
      flag = true;
      critical_section();
      flag = false;
    }

    The day finally came. The Deadlock Empire opened its gates and from them surged massive amounts of soldiers, loyal servants of the evil Parallel Wizard. The Wizard has many strengths - his armies are fast, and he can do a lot of stuff that we can't. But now he set out to conquer the world, and we cannot have that.

    You are our best Scheduler, commander! We have fewer troops and simpler ones, so we will need your help. Already two armies of the Deadlock Empire are approaching our border keeps. They are poorly equipped and poorly trained, however. You might be able to desync them and break their morale.

    j123123, 20 Февраля 2021

    Комментарии (60)
  5. Си / Говнокод #27255

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    int main(void)
    {
      uint32_t uint32max = UINT32_MAX;
      int32_t int32_minus_one = -1;
      printf("uint32_max = %" PRIu32 "\n", uint32max);
      printf("int32_minus_one = %" PRIi32 "\n", int32_minus_one);
      if (uint32max > int32_minus_one)
      {
        puts("uint32max > int32_minus_one");
      }
      else if (uint32max < int32_minus_one)
      {
        puts("uint32max < int32_minus_one");
      }
      else
      {
        puts("uint32max == int32_minus_one");
      }
      return EXIT_SUCCESS;
    }

    Почему в Си нет особого правила при сравнении signed и unsigned типов, ну типа если значение в signed типе отрицательно, то он полюбасу будет меньше любого unsigned значения? А то говно какое-то.

    (нет, я понимаю почему так происходит, но все равно говно)

    j123123, 15 Февраля 2021

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

    0

    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
    // https://github.com/google/ruy/blob/2887692065c38ef6617f423feafc6b69dd0a0681/ruy/pack_avx2_fma.cc#L66
    
    inline void Pack8bitColMajorForAvx2Packer(
        const std::int8_t* src_ptr, std::int8_t input_xor,
        const std::int8_t* zerobuf, int src_stride, int remaining_src_cols,
        int src_rows, std::int8_t* packed_ptr, std::int32_t* sums_ptr,
        std::int8_t* trailing_buf) {
      using Layout = PackImpl8bitAvx2::Layout;
      RUY_DCHECK_EQ(Layout::kCols, 8);
      RUY_DCHECK_EQ(Layout::kRows, 4);
      // Each Layout::Rows is 4 contiguous input, contiguous packed elements.
      // We process 8 of these chunks at a time, padding short input chunks.
      constexpr int kNumRowChunks = 8;
      constexpr int kNumChunkedSrcRows = kNumRowChunks * Layout::kRows;
    
      const std::int8_t* src_ptr0 = src_ptr;
      const std::int8_t* src_ptr1 = src_ptr0 + src_stride;
      const std::int8_t* src_ptr2 = src_ptr1 + src_stride;
      const std::int8_t* src_ptr3 = src_ptr2 + src_stride;
      const std::int8_t* src_ptr4 = src_ptr3 + src_stride;
      const std::int8_t* src_ptr5 = src_ptr4 + src_stride;
      const std::int8_t* src_ptr6 = src_ptr5 + src_stride;
      const std::int8_t* src_ptr7 = src_ptr6 + src_stride;
      std::int64_t src_inc0 = kNumChunkedSrcRows;
      std::int64_t src_inc1 = kNumChunkedSrcRows;
      std::int64_t src_inc2 = kNumChunkedSrcRows;
      std::int64_t src_inc3 = kNumChunkedSrcRows;
      std::int64_t src_inc4 = kNumChunkedSrcRows;
      std::int64_t src_inc5 = kNumChunkedSrcRows;
      std::int64_t src_inc6 = kNumChunkedSrcRows;
      std::int64_t src_inc7 = kNumChunkedSrcRows;
      // Handle cases where source does not have Layout::kCols (8) columns.
      if (remaining_src_cols < 8) {
        if (remaining_src_cols <= 0) {
          src_ptr0 = zerobuf;
          src_inc0 = 0;
        }
        if (remaining_src_cols <= 1) {
          src_ptr1 = zerobuf;
          src_inc1 = 0;
        }
        if (remaining_src_cols <= 2) {
          src_ptr2 = zerobuf;
          src_inc2 = 0;
        }
        if (remaining_src_cols <= 3) {
          src_ptr3 = zerobuf;
          src_inc3 = 0;
        }
        if (remaining_src_cols <= 4) {
          src_ptr4 = zerobuf;
          src_inc4 = 0;
        }
        if (remaining_src_cols <= 5) {
          src_ptr5 = zerobuf;
          src_inc5 = 0;
        }
        if (remaining_src_cols <= 6) {
          src_ptr6 = zerobuf;
          src_inc6 = 0;
        }
        src_ptr7 = zerobuf;
        src_inc7 = 0;
      }
    
      const std::int8_t zero_point = zerobuf[0];
    
      if (sums_ptr) {
        // i: Layout::kCols.
        for (int i = 0; i < 8; ++i) {
          sums_ptr[i] = 0;
        }
      }
      std::int32_t sums_adjustment = 0;
      const __m256i ones_16bit = _mm256_set1_epi16(1);
      __m256i sums_4x2_32bit_lo = _mm256_set1_epi32(0);
      __m256i sums_4x2_32bit_hi = _mm256_set1_epi32(0);
    
      // The overall packing effectively pads the source rows to
      // (src_rows + 63) & ~63. The iteration over k may skip when m=1, and then we
      // only pack for (src_rows + 31) & ~31. When there is an incomplete
      // destination block, this is stored into trailing_buf instead of packed_ptr.
      for (int k = 0; k < src_rows; k += kNumChunkedSrcRows) {
        // Available source rows.
        // If this is less than 0 (for m=1), we skip, having filled trailing
        // buffer for m=0. Also, if source rows is zero on m=1, then we filled
        // exactly to the end of the column in the packed buffer.
        const int available_src_rows = src_rows - k;
        // Effectively,
        // available rows = std::max(0, std::min(8, src_rows - k));
        // treat each case separately.
        if (available_src_rows >= kNumChunkedSrcRows) {
          if (sums_ptr) {
            __m256i t0, t1, t2, t3, t4, t5, t6, t7;
            __m256i r0, r1, r2, r3, r4, r5, r6, r7;
            const __m256i input_xor_v = _mm256_set1_epi8(input_xor);
    
            t0 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr0));
            t4 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr4));
            t1 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr1));

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

    j123123, 08 Февраля 2021

    Комментарии (17)
  7. Си / Говнокод #27240

    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
    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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    // https://github.com/ARMmbed/mbedtls/blob/a0832d47f7eb859f75301ae321be5dea4ccb17f3/library/aes.c#L128
    
    /*
     * Forward tables
     */
    #define FT \
    \
        V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \
        V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \
        V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \
        V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \
        V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \
        V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \
        V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \
        V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \
        V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \
        V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \
        V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \
        V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \
        V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \
        V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \
        V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \
        V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \
        V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \
        V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \
        V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \
        V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \
        V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \
        V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \
        V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \
        V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \
        V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \
        V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \
        V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \
        V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \
        V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \
        V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \
        V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \
        V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \
        V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \
        V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \
        V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \
        V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \
        V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \
        V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \
        V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \
        V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \
        V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \
        V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \
        V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \
        V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \
        V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \
        V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \
        V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \
        V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \
        V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \
        V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \
        V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \
        V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \
        V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \
        V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \
        V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \
        V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \
        V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \
        V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \
        V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \
        V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \
        V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \
        V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \
        V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \
        V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C)
    
    
    #define V(a,b,c,d) 0x##a##b##c##d
    static const uint32_t FT0[256] = { FT };
    #undef V
    
    #if !defined(MBEDTLS_AES_FEWER_TABLES)
    
    #define V(a,b,c,d) 0x##b##c##d##a
    static const uint32_t FT1[256] = { FT };
    #undef V
    
    #define V(a,b,c,d) 0x##c##d##a##b
    static const uint32_t FT2[256] = { FT };
    #undef V
    
    #define V(a,b,c,d) 0x##d##a##b##c
    static const uint32_t FT3[256] = { FT };
    #undef V

    Какая генерация )))
    Крестобляди б наверное тут какими-то констэкспрами делали нужные кобенации битиков. А тут прость через перегрузку переопределение дефайна можно по-разному байтики сшивать.

    j123123, 07 Февраля 2021

    Комментарии (9)
  8. C++ / Говнокод #27234

    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
    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
    // https://github.com/WebKit/WebKit/blob/31b77296cf6d85c40313812d9f65a003cf41f440/Source/WebCore/page/Quirks.cpp#L330
    
    bool Quirks::isGoogleMaps() const
    {
        auto& url = m_document->topDocument().url();
        return topPrivatelyControlledDomain(url.host().toString()).startsWith("google.") && url.path().startsWithIgnoringASCIICase("/maps/");
    }
    
    bool Quirks::shouldDispatchSimulatedMouseEvents() const
    {
        if (RuntimeEnabledFeatures::sharedFeatures().mouseEventsSimulationEnabled())
            return true;
    
        if (!needsQuirks())
            return false;
    
        auto doShouldDispatchChecks = [this] () -> bool {
            auto* loader = m_document->loader();
            if (!loader || loader->simulatedMouseEventsDispatchPolicy() != SimulatedMouseEventsDispatchPolicy::Allow)
                return false;
    
            if (isAmazon())
                return true;
            if (isGoogleMaps())
                return true;
    
            auto& url = m_document->topDocument().url();
            auto host = url.host().convertToASCIILowercase();
    
            if (host == "wix.com" || host.endsWith(".wix.com")) {
                // Disable simulated mouse dispatching for template selection.
                return !url.path().startsWithIgnoringASCIICase("/website/templates/");
            }
    
            if ((host == "desmos.com" || host.endsWith(".desmos.com")) && url.path().startsWithIgnoringASCIICase("/calculator/"))
                return true;
            if (host == "figma.com" || host.endsWith(".figma.com"))
                return true;
            if (host == "trello.com" || host.endsWith(".trello.com"))
                return true;
            if (host == "airtable.com" || host.endsWith(".airtable.com"))
                return true;
            if (host == "msn.com" || host.endsWith(".msn.com"))
                return true;
            if (host == "flipkart.com" || host.endsWith(".flipkart.com"))
                return true;
            if (host == "iqiyi.com" || host.endsWith(".iqiyi.com"))
                return true;
            if (host == "trailers.apple.com")
                return true;
            if (host == "soundcloud.com")
                return true;
            if (host == "naver.com")
                return true;
            if (host == "nba.com" || host.endsWith(".nba.com"))
                return true;
            if (host.endsWith(".naver.com")) {
                // Disable the quirk for tv.naver.com subdomain to be able to simulate hover on videos.
                if (host == "tv.naver.com")
                    return false;
                // Disable the quirk for mail.naver.com subdomain to be able to tap on mail subjects.
                if (host == "mail.naver.com")
                    return false;
                // Disable the quirk on the mobile site.
                // FIXME: Maybe this quirk should be disabled for "m." subdomains on all sites? These are generally mobile sites that don't need mouse events.
                if (host == "m.naver.com")
                    return false;
                return true;
            }
            return false;
        };
    
        if (!m_shouldDispatchSimulatedMouseEventsQuirk)
            m_shouldDispatchSimulatedMouseEventsQuirk = doShouldDispatchChecks();
        return *m_shouldDispatchSimulatedMouseEventsQuirk;
    }

    Дааа блядь, давайте в движке браузера захардкодим какие-то говнодомены, что типа вот для них какая-то там блядь симуляция событий мыши работала каким-то таким образом. Охуенно!

    j123123, 04 Февраля 2021

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

    +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
    // https://quuxplusone.github.io/blog/2021/01/13/conversion-operator-lookup/
    
    struct A {
        using T = T1;
        using U = U1;
        operator U1 T1::*();
        operator U1 T2::*();
        operator U2 T1::*();
        operator U2 T2::*();
    };
    
    inline auto which(U1 T1::*) { return "gcc"; }
    inline auto which(U1 T2::*) { return "icc"; }
    inline auto which(U2 T1::*) { return "msvc"; }
    inline auto which(U2 T2::*) { return "clang"; }
    
    int main() {
        A a;
        using T = T2;
        using U = U2;
        puts(which(a.operator U T::*()));
    }

    > As of this writing (but perhaps not for very much longer!) the four mainstream compilers on Godbolt Compiler Explorer give four different answers for this simple C++ program:

    > According to the current draft standard, it sounds like the conforming answer is “they should both be looked up in the scope of A”; i.e., GCC’s answer is correct and the others are wrong in three different ways.

    Какой багор )))

    j123123, 21 Января 2021

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

    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
    // https://www.linux.org.ru/forum/development/16099510/
    // c++ шаблон zip-like итератора? 
    // В python есть крайне полезные функции zip, enumerate, range. Мне нужно что-то подобное для cpp/cuda (c++17).
    // Если c range и enumerate более менее понятно, то как реализовать zip не соображу. Семантически это должно быть variadic template
    
    template<typename t, typename... ts>
    class zip : zip<ts...>{
    	zip(t arg, ts... args);
    	struct iterator;
    	begin() -> iterator;
    	end()   -> iterator;
    };
    
    // Где итератор возвращает кортеж ссылок на элементы что с контейнерами можно было работать как:
    
    for(auto [x,y,z] : zip(xs,ys,zs))
    
    // Рекурсивное наследование должно быть ограничено тривиальным случаем одного аргумента.
    //Но, кажется, я думаю не в правильную сторону, в частности, не соображу как рекурсивно вывести тип возвращаемых итератором кортежей:
    
    using ret_type = tuple<decltype(begin(declval<t>())), decltype(???)>

    Блять, как всё сложно. Какие-то рекурсивные выводы типов возвращаемых итераторов кортежей блядь.

    Вот если б вместо ущербного триждыблядского типодрочерского шаблоноговна сделали что-то помощнее...

    j123123, 11 Января 2021

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

    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
    void s_sort(int *a, size_t sz)
    {
      if ((sz == 0) || (sz == 1))
      {
        return;
      }
      if (sz  == 2)
      {
        int a_max = a[0] > a[1] ? a[0] : a[1];
        int a_min = a[0] > a[1] ? a[1] : a[0];
        a[0] = a_min;
        a[1] = a_max;
        return;
      }
      s_sort(a, sz - 1);
      s_sort(a + 1, sz - 1);
      s_sort(a, sz - 1);
    }

    Крайне тупая по своей сути рекурсивная сортировка. Есть ли у нее название?

    Вряд ли она имеет какое-то практическое применение именно как сортировка, но зато можно ее переписать на какой-нибудь Coq и об нее доказывать другие сортировки. Типа если какая-то там другая сортировка на всех возможных входных массивах выдает то же, что и выдает вот эта сортировка, то сортировка правильная.

    j123123, 03 Января 2021

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