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

    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
    // https://github.com/microsoft/Windows-driver-samples/blob/d3ec258921cfcef7b053b5a2c866330d43dd3f03/filesys/fastfat/dumpsup.c#L35
    
    #define DumpLabel(Label,Width) {                                          \
        size_t i, LastPeriod=0;                                                \
        CHAR _Str[20];                                                        \
        for(i=0;i<2;i++) { _Str[i] = UCHAR_SP;}                               \
        for(i=0;i<strlen(#Label);i++) {if (#Label[i] == '.') LastPeriod = i;} \
        strncpy(&_Str[2],&#Label[LastPeriod],Width);                          \
        for(i=strlen(_Str);i<Width;i++) {_Str[i] = UCHAR_SP;}                 \
        _Str[Width] = '\0';                                                   \
        DbgPrint("%s", _Str);                                                  \
    }
    
    #define DumpField(Field) {                                         \
        if ((FatDumpCurrentColumn + 18 + 9 + 9) > 80) {DumpNewLine();} \
        FatDumpCurrentColumn += 18 + 9 + 9;                            \
        DumpLabel(Field,18);                                           \
        DbgPrint(":%p", Ptr->Field);                                  \
        DbgPrint("         ");                                          \
    }
    
    #define DumpListEntry(Links) {                                     \
        if ((FatDumpCurrentColumn + 18 + 9 + 9) > 80) {DumpNewLine();} \
        FatDumpCurrentColumn += 18 + 9 + 9;                            \
        DumpLabel(Links,18);                                           \
        DbgPrint(":%p", Ptr->Links.Flink);                            \
        DbgPrint(":%p", Ptr->Links.Blink);                            \
    }
    
    #define DumpName(Field,Width) {                                    \
        ULONG i;                                                       \
        CHAR _String[256];                                             \
        if ((FatDumpCurrentColumn + 18 + Width) > 80) {DumpNewLine();} \
        FatDumpCurrentColumn += 18 + Width;                            \
        DumpLabel(Field,18);                                           \
        for(i=0;i<Width;i++) {_String[i] = (CHAR)Ptr->Field[i];}             \
        _String[Width] = '\0';                                         \
        DbgPrint("%s", _String);                                        \
    }
    
    #define TestForNull(Name) {                                 \
        if (Ptr == NULL) {                                      \
            DbgPrint("%s - Cannot dump a NULL pointer\n", Name); \
            return;                                             \
        }                                                       \
    }

    Макроговно от мекомягких для отладки файловой системы FAT

    j123123, 22 Ноября 2021

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

    0

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

    #104: https://govnokod.ru/27534 https://govnokod.xyz/_27534
    #105: https://govnokod.ru/27544 https://govnokod.xyz/_27544
    #106: https://govnokod.ru/27552 https://govnokod.xyz/_27552
    #107: https://govnokod.ru/27554 https://govnokod.xyz/_27554
    #108: https://govnokod.ru/27557 https://govnokod.xyz/_27557
    #109: https://govnokod.ru/27581 https://govnokod.xyz/_27581
    #110: https://govnokod.ru/27610 https://govnokod.xyz/_27610
    #111: https://govnokod.ru/27644 https://govnokod.xyz/_27644
    #112: https://govnokod.ru/27648 https://govnokod.xyz/_27648
    #113: https://govnokod.ru/27652 https://govnokod.xyz/_27652
    #114: https://govnokod.ru/27659 https://govnokod.xyz/_27659
    #115: https://govnokod.ru/27665 https://govnokod.xyz/_27665
    #116: https://govnokod.ru/27671 https://govnokod.xyz/_27671
    #117: https://govnokod.ru/27675 https://govnokod.xyz/_27675
    #118: https://govnokod.ru/27685 https://govnokod.xyz/_27685
    #119: https://govnokod.ru/27701 https://govnokod.xyz/_27701
    #120: https://govnokod.ru/27703 https://govnokod.xyz/_27703
    #121: https://govnokod.ru/27710 https://govnokod.xyz/_27710
    #122: https://govnokod.ru/27728 https://govnokod.xyz/_27728
    #123: https://govnokod.ru/27729 https://govnokod.xyz/_27729
    #124: https://govnokod.ru/27730 https://govnokod.xyz/_27730
    #125: https://govnokod.ru/27732 https://govnokod.xyz/_27732
    #126: https://govnokod.ru/27733 https://govnokod.xyz/_27733
    #127: https://govnokod.ru/27737 https://govnokod.xyz/_27737
    #128: https://govnokod.ru/27742 https://govnokod.xyz/_27742
    #129: https://govnokod.ru/27747 https://govnokod.xyz/_27747
    #130: https://govnokod.ru/27755 https://govnokod.xyz/_27755
    #131: https://govnokod.ru/27766 https://govnokod.xyz/_27766
    #132: https://govnokod.ru/27790 https://govnokod.xyz/_27790
    #133: https://govnokod.ru/27828 https://govnokod.xyz/_27828

    nepeKamHblu_nemyx, 21 Ноября 2021

    Комментарии (570)
  3. Куча / Говнокод #27833

    0

    1. 1
    Пиздец-оффтоп #38

    #8: https://govnokod.ru/27023 https://govnokod.xyz/_27023
    #9: https://govnokod.ru/27098 https://govnokod.xyz/_27098
    #10: https://govnokod.ru/27125 https://govnokod.xyz/_27125
    #11: https://govnokod.ru/27129 https://govnokod.xyz/_27129
    #12: https://govnokod.ru/27184 https://govnokod.xyz/_27184
    #13: https://govnokod.ru/27286 https://govnokod.xyz/_27286
    #14: https://govnokod.ru/27298 https://govnokod.xyz/_27298
    #15: https://govnokod.ru/27322 https://govnokod.xyz/_27322
    #16: https://govnokod.ru/27328 https://govnokod.xyz/_27328
    #17: https://govnokod.ru/27346 https://govnokod.xyz/_27346
    #18: https://govnokod.ru/27374 https://govnokod.xyz/_27374
    #19: https://govnokod.ru/27468 https://govnokod.xyz/_27468
    #20: https://govnokod.ru/27469 https://govnokod.xyz/_27469
    #21: https://govnokod.ru/27479 https://govnokod.xyz/_27479
    #22: https://govnokod.ru/27485 https://govnokod.xyz/_27485
    #23: https://govnokod.ru/27493 https://govnokod.xyz/_27493
    #24: https://govnokod.ru/27501 https://govnokod.xyz/_27501
    #25: https://govnokod.ru/27521 https://govnokod.xyz/_27521
    #26: https://govnokod.ru/27545 https://govnokod.xyz/_27545
    #27: https://govnokod.ru/27572 https://govnokod.xyz/_27572
    #28: https://govnokod.ru/27580 https://govnokod.xyz/_27580
    #29: https://govnokod.ru/27738 https://govnokod.xyz/_27738
    #30: https://govnokod.ru/27751 https://govnokod.xyz/_27751
    #31: https://govnokod.ru/27754 https://govnokod.xyz/_27754
    #32: https://govnokod.ru/27786 https://govnokod.xyz/_27786
    #33: https://govnokod.ru/27801 https://govnokod.xyz/_27801
    #34: https://govnokod.ru/27817 https://govnokod.xyz/_27817
    #35: https://govnokod.ru/27822 https://govnokod.xyz/_27822
    #36: https://govnokod.ru/27826 https://govnokod.xyz/_27826
    #37: https://govnokod.ru/27827 https://govnokod.xyz/_27827

    nepeKamHblu_nemyx, 21 Ноября 2021

    Комментарии (604)
  4. SQL / Говнокод #27832

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    SELECT *
    FROM TRANSACTION
    WHERE status = 'in-check'
      AND created >= '2021-11-17 12:40'
      AND created <= '2021-11-17 01:10';

    Когда очень полюбили 12-часовой формат

    alex_ok, 19 Ноября 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    Rectangle {
        id: round
        height: ~~(parent.height / 2)
        width: height
        anchors.centerIn: parent
        color: "blue"
        radius: width / 2 - 1  // Радиус скругления углов
    }

    QML.
    Мне кажется, что каждый раз, когда я использую элемент Rectangle, чтобы нарисовать кружок, кому-то где-то приходится приваривать к верхнему днищу бака треугольное отверстие диаметром три на четыре...
    Алсо, оператор хвостик (чтобы избежать субпиксельной границы).

    Steve_Brown, 19 Ноября 2021

    Комментарии (1)
  6. Куча / Говнокод #27830

    −2

    1. 1
    Прискорбно мне от мысли, что админ сайта сия оказался таким пропутинским маргиналом.

    Страйко, зачем ты удалил мой пост про куар коды? М?

    MaaKut, 18 Ноября 2021

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

    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
    (steps
    (1 given (t (((x - y) = 3) & ((y + 5) = x))))
    (2 rewrite (s 1) (path "/main/right/right") (t ((x = y) == (y = x))))
    (3 addThisToBoth (s 2) (path "/main/right/left/left/right"))
    (4 arrangeSum (s 3) (path "/right/right/left/right"))
    (5 simplifySite (s 4) (path "/right/right/left/left"))
    (6 replaceConjunct (s 5) (path "/right/right/left/left"))
    (7 subtractThisFromBoth (s 6) (path "/right/right/left/left/left"))
    (8 arrangeSum (s 7) (path "/right/right/left/right"))
    (9 simplifySite (s 8) (path "/right/right/left/right"))
    (10 arrangeSum (s 9) (path "/right/right/left/left"))
    (11 simplifySite (s 10) (path "/right/right/left/left"))
    (12 rewrite (s 11) (path "/right/right/left") (t (((R a) & (R b)) => ((a = b) == ((a - b) = 0)))))
    (13 simplifyFocalPart (s 12))
    (14 modusPonens (s 1) (s 13))
    )

    https://mathtoys.org/equations.html
    Доказательство неразрешимости системы уравнений
    x-y=3
    y=5=x
    Где x и y это ℝ
    https://i.imgur.com/oY4FXTN.png

    j123123, 17 Ноября 2021

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

    +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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    #include <limits.h>
    typedef unsigned __int128 uint128_t;
    typedef __int128 int128_t;
    
    // в чем тут по-вашему баг ?
    uint64_t add1bit_left_1_bug(const uint64_t a, int shift)
    {
      return ~(~(a << shift) >> shift);
    }
    
    uint64_t add1bit_left_1(const uint64_t a, int shift)
    {
      return ~((uint128_t)~(uint64_t)((uint128_t)a << shift) >> shift);
    }
    
    // или тут ?
    uint64_t add1bit_left_2_bug(const uint64_t a, int shift)
    {
      return a | (uint64_t)(UINT64_MAX << (CHAR_BIT * sizeof(uint64_t) - shift));
    }
    
    uint64_t add1bit_left_2(const uint64_t a, int shift)
    {
      return a | (uint64_t)((uint128_t)-1 << (CHAR_BIT * sizeof(uint64_t) - shift));
    }
    
    uint64_t add1bit_left_3(const uint64_t a, int shift)
    {
      if (shift == 0) return a;
      return (uint64_t)((int64_t)((a << (shift-1)) | ((uint64_t)1 << (CHAR_BIT * sizeof(uint64_t) - 1)) ) >> (shift-1)); // а тут вообще UB
    }
    
    
    int main(void)
    {
      // tests
      for (int i = 0; i <= 64; i++) // пробуем сдвигать от 0 до 64 включительно.
      {
        // for (uint128_t j = 0; j < UINT64_MAX+1; j++) - какая формальная верификация )))
        for (uint64_t j = 0; j < 100; j++)
        {
          if (add1bit_left_1(j,i) != add1bit_left_2(j,i))
          {
            printf("error1\n");
            printf("%" PRIu64 " %d\n", j,i);
            return EXIT_FAILURE;
          }
          if (add1bit_left_1(j,i) != add1bit_left_3(j,i))
            printf("error2\n");
          if (add1bit_left_2(j,i) != add1bit_left_3(j,i))
            printf("error3\n");
        }
      }
      printf("%" PRIX64 "\n", add1bit_left_1(0,0));
      printf("%" PRIX64 "\n", add1bit_left_2(0,0));
      printf("%" PRIX64 "\n", add1bit_left_3(0,0));
      printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,0));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,0));
      puts("");
      printf("%" PRIX64 "\n", add1bit_left_1(0,1));
      printf("%" PRIX64 "\n", add1bit_left_2(0,1));
      printf("%" PRIX64 "\n", add1bit_left_3(0,1));
      printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,1));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,1));
      puts("");
      printf("%" PRIX64 "\n", add1bit_left_1(0,2));
      printf("%" PRIX64 "\n", add1bit_left_2(0,2));
      printf("%" PRIX64 "\n", add1bit_left_3(0,2));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,2));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,2));
      puts("");
      printf("%" PRIX64 "\n", add1bit_left_1(0,64));
      printf("%" PRIX64 "\n", add1bit_left_2(0,64));
      printf("%" PRIX64 "\n", add1bit_left_3(0,64));
      printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,64));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,64));
      return EXIT_SUCCESS;
    }

    Вореанты говнофункции, которая сдвигает влево uint64_t но набрасывает единички вместо ноликов.

    j123123, 17 Ноября 2021

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

    +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
    // @param n `0 <= n`
    // @param m `1 <= m`
    // @return `(x ** n) % m`
    constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
        if (m == 1) return 0;
        unsigned int _m = (unsigned int)(m);
        unsigned long long r = 1;
        unsigned long long y = safe_mod(x, m);
        while (n) {
            if (n & 1) r = (r * y) % _m;
            y = (y * y) % _m;
            n >>= 1;
        }
        return r;
    }
     
    // Reference:
    // M. Forisek and J. Jancina,
    // Fast Primality Testing for Integers That Fit into a Machine Word
    // @param n `0 <= n`
    constexpr bool is_prime_constexpr(int n) {
        if (n <= 1) return false;
        if (n == 2 || n == 7 || n == 61) return true;
        if (n % 2 == 0) return false;
        long long d = n - 1;
        while (d % 2 == 0) d /= 2;
        constexpr long long bases[3] = {2, 7, 61};
        for (long long a : bases) {
            long long t = d;
            long long y = pow_mod_constexpr(a, t, n);
            while (t != n - 1 && y != 1 && y != n - 1) {
                y = y * y % n;
                t <<= 1;
            }
            if (y != n - 1 && t % 2 == 0) {
                return false;
            }
        }
        return true;
    }
    template <int n> constexpr bool is_prime = is_prime_constexpr(n);

    https://codeforces.com/contest/1508/submission/113222414

    > if (n == 2 || n == 7 || n == 61) return true;

    Помню я как делал: подобрал 3 базовых числа, прогнал на всех интах, там где алгоритм ошибался - проифал вручную )))

    3_dar, 14 Ноября 2021

    Комментарии (44)
  10. PHP / Говнокод #27821

    −6

    1. 1
    2. 2
    3. 3
    Подписывайтесь на канал Говнокода в телеграме:
    
    https://t.me/GovnokodChannel

    guest6, 14 Ноября 2021

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