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

    Всего: 343

  2. C++ / Говнокод #24542

    +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
    // Non-constant constant-expressions in C++
    // http://b.atch.se/posts/non-constant-constant-expressions/
    // The Implementation
    
    constexpr int flag (int);
    
    template<class Tag>
    struct writer {
      friend constexpr int flag (Tag) {
        return 0;
      }
    };
    
    template<bool B, class Tag = int>
    struct dependent_writer : writer<Tag> { };
    
    template<
      bool B = noexcept (flag (0)),
      int    =   sizeof (dependent_writer<B>)
    >
    constexpr int f () {
      return B;
    }
    
    int main () {
      constexpr int a = f ();
      constexpr int b = f ();
    
      static_assert (a != b, "fail");
    }

    Note: clang incorrectly shows the wrong behavior, a workaround is available in the appendix.

    j123123, 26 Июля 2018

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

    −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
    // https://github.com/Qqwy/raii_with/blob/74e4c66a821fba6a483d62a8c583b3fab06e3443/raii/raii.h#L60
    
    /**
     * Custom Control Structure Macro to provide Resource Acquisition Is Initialization (and Resource Relinquishment is Destruction).
     *
     * Use this to run a block of code with `var_decl` initialized to `init`, where at the end of the block (or at an earlier `safe_return`),
     * the passed `destr`-function will automatically be called with the given resource.
     *
     * Gotcha's:
     * 1. Do not use `return` from within `raii_with`, but only `safe_return`, because otherwise the destructors will not be run.
     * 2. Do not perform pointer-swaps with `var_decl`; the destructor will still be run on the original structure, because `raii` keeps its own reference to the resource.
     */
    #define raii_with(var_decl, init, destr)                                \
      while(1) /* i.c.m. break on l.4, so we can jump past the user-supplied block */ \
        if(0)                                                               \
        raii_glue(__raii_with_finished, __LINE__):                              \
          break;                                                            \
        else                                                                \
          /* initialize _tmp lifetime list elem so replacement `raii_lifetime_list` can have previous one as tail. */ \
          for(struct raii_lifetime_list_t _tmp = {.elem.resource = init, .elem.destructor = destr, .next = raii_lifetime_list};;) \
            /* initialize user-supplied variable name */                    \
            for(var_decl = _tmp.elem.resource;;)                            \
              if (1) {                                                      \
                /* Fill `_tmp`'s tail before `raii_lifetime_list` is shadowed */ \
                _tmp.next = raii_lifetime_list;                             \
                goto raii_glue(__raii_with_setup, __LINE__);                    \
              } else                                                        \
              raii_glue(__raii_with_setup, __LINE__):                           \
                /* Shadow `raii_lifetime_list` with inner version */        \
                for(struct raii_lifetime_list_t *raii_lifetime_list = &_tmp;;) \
                  if(1){                                                    \
                    goto raii_glue(__raii_with_body, __LINE__);                 \
                  } else                                                    \
                    while (1) /* so break works as expected */              \
                      while (1) /*so continue works as expected */          \
                        if (1){                                             \
                          /*after the else-block (or break or continue), destruct and finish */ \
                          destruct_raii_lifetime(raii_lifetime_list->elem); \
                          goto raii_glue(__raii_with_finished, __LINE__);       \
                        } else                                              \
                        raii_glue(__raii_with_body, __LINE__):
    
    
    #endif // RAII_WITH_H

    raii

    A simple library to provide RAII in standard-compliant C99, using raii_with(resource, initializer, destructor) { ... }-syntax:

    j123123, 19 Июля 2018

    Комментарии (244)
  4. C++ / Говнокод #24501

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // https://habr.com/company/JetBrains/blog/249479/
    
    Привет, Хабр!
    
    Некоторое время назад мы объявили конкурс — требовалось продолжить фразу:
    Бьёрн Страуструп создал С++ 36 лет назад, и он до сих пор востребован и пользуется популярностью у разработчиков, потому что...
    
    Спасибо всем участникам за массу положительных эмоций и разнообразные предположения о том, что же сделало C++ таким популярным.

    Посовещавшись, мы выбрали топ-6 ответов:

    j123123, 16 Июля 2018

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

    +5

    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
    void sort3(uint32_t a[static 3])
    {
      //                   0     1     2     3     4     5     6     7     8
      uint32_t tmp[9] = {a[0], a[1], a[2], a[0], a[1], a[0], a[2], a[1], a[0]};
      uint8_t bits = (a[0] <= a[1]) | ((a[1] <= a[2]) << 1) | ((a[0] <= a[2]) << 2);
      static const uint8_t b[] =
      {
        [0b000] = 6,
        [0b001] = 2,
        [0b010] = 1,
        [0b101] = 5,
        [0b110] = 4,
        [0b111] = 0,
      };
      memcpy(a, tmp+b[bits], 3*sizeof(uint32_t));
    }

    Новая инновационная сортировка на 3 элемента без if-ов
    https://wandbox.org/permlink/pTLXgxKKQuaiVCxb

    j123123, 15 Июля 2018

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

    +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
    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
    // https://habr.com/post/417027/
    // Как я стандартную библиотеку C++11 писал или почему boost такой страшный
    // https://github.com/oktonion/stdex/blob/1472fd5e2f5e0d10a136518631055c3aad2e1cfd/stdex/include/thread.hpp#L51
    
    
    		template<class R, class T1>
    		struct _function_traits<R(*)(T1)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T1 argument_type;
    		};
    
    		template<class R, class T1, class T2>
    		struct _function_traits<R(*)(T1, T2)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T2 arg2_type;
    			
    			
    		};
    
    		template<class R, class T1, class T2, class T3>
    		struct _function_traits<R(*)(T1, T2, T3)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T2 arg2_type;
    			typedef T3 arg3_type;
    		};
    
    		template<class R, class T1, class T2, class T3, class T4>
    		struct _function_traits<R(*)(T1, T2, T3, T4)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T2 arg2_type;
    			typedef T3 arg3_type;
    			typedef T4 arg4_type;
    		};
    
    		template<class R, class T1, class T2, class T3, class T4,
    			class T5>
    		struct _function_traits<R(*)(T1, T2, T3, T4, T5)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T2 arg2_type;
    			typedef T3 arg3_type;
    			typedef T4 arg4_type;
    			typedef T5 arg5_type;
    		};
    
    		template<class R, class T1, class T2, class T3, class T4,
    			class T5, class T6>
    		struct _function_traits<R(*)(T1, T2, T3, T4, T5, T6)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T2 arg2_type;
    			typedef T3 arg3_type;
    			typedef T4 arg4_type;
    			typedef T5 arg5_type;
    			typedef T6 arg6_type;
    		};
    
    		template<class R, class T1, class T2, class T3, class T4,
    			class T5, class T6, class T7>
    		struct _function_traits<R(*)(T1, T2, T3, T4, T5, T6, T7)>
    		{
    			typedef R result_type;
    			typedef T1 arg1_type;
    			typedef T2 arg2_type;
    			typedef T3 arg3_type;
    			typedef T4 arg4_type;
    			typedef T5 arg5_type;
    			typedef T6 arg6_type;
    			typedef T7 arg7_type;
    		};
    
    ...

    > На дворе был 2017 год! Уже C++ 17 активно вводился в GCC, clang, Visual Studio, везде был decltype (since C++ 11), constexpr (since C++ 11, но существенно доработан), модули уже почти на подходе, хорошее время было. Я же находился на работе и с некоторым неодобрением смотрел на очередной Internal Compiler Error в своем Borland C++ Builder 6.0, а так же на множество ошибок сборки с очередной версией библиотеки boost. Думаю, теперь вы понимаете, откуда взялась эта тяга к велосипедостроению. У нас использовался Borland C++ Builder 6.0 и Visual Studio 2010 под Windows, g++ версии 4.4.2 или ниже под QNX и под некоторые unix системы. От MacOS мы были избавлены, что несомненно было плюсом. Ни о каких других компиляторах (под C++ 11 в том числе) речи даже быть не могло по соображениям, которые мы оставим за пределами данной статьи.

    > «А что там может быть на столько сложного» — закралась мысль в мой измученный попытками завести boost под старый-добрый builder мозг. «Мне всего то нужно type_traits, thread, mutex, возможно chrono, nullptr было бы еще неплохо.» — рассудил я и принялся за работу.

    j123123, 13 Июля 2018

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

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    void test1(void)
    {
      printf("test1\n");
    }
    void test2(void)
    {
      printf("test2\n");
    }
    void test3(void)
    {
      printf("test3\n");
    }
    void test4(void)
    {
      printf("test4\n");
    }
    
    uint8_t func_dist[3] = {(uint8_t)((char *)test2-(char *)test1), (uint8_t)((char *)test3-(char *)test2), (uint8_t)((char *)test4-(char *)test3)};
    
    void callf(uint8_t fn)
    {
      size_t sum_dis = 0;
      for (uint8_t i = 0; i < fn; i++)
      {
        sum_dis += func_dist[i];
      }
      ( (void(*)(void)) ((char *)test1+sum_dis) )  ();
    }
    
    int main(void)
    {
      callf(0);
      callf(1);
      callf(2);
      callf(3);
      return EXIT_SUCCESS;
    }

    Зожатие указателей. Главное чтоб длины функций не превышали 255 и чтоб функции шли строго подряд, как они объявлены кода
    Как сделать чтобы это компилировалось сишкой?

    j123123, 10 Июля 2018

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

    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
    void check_manifest_line (int p) {
      static char c[MAX_LINE_LEN + 1];
      int l = p - START_MANIFEST_POSITION;
      if (l <= MAX_LINE_LEN && l > 4) {
        get_binlog_data (c, START_MANIFEST_POSITION, l);
        c[l] = 0;
        char *pp = c;
        int op = -1;
        if (l >= 6 && !memcmp (c, "start", 5)) {
          op = 1; 
          pp += 5;
        } else if (l >= 5 && !memcmp (c, "stop", 4)) {
          op = 2;
          pp += 4;
        } else if (l >= 8 && !memcmp (c, "version", 7)) {
          op = 3;
          pp += 7;
        }
        if (is_whitespace (*pp) && op > 0) {      
          pp ++;
          pp = eat_whitespace (pp);
          if (!*pp) {
            START_MANIFEST_POSITION = p + 1;
            return;
          }
          if (op == 1 || op == 2) {
            char *rr = pp;
            pp = eat_not_whitespace (pp);
            char *zz = pp;
            pp = eat_whitespace (pp);
            *zz = 0;
            if (pp == c + l && zz - rr > 0) {
              struct cluster *C = CC;
              int x = BINLOG_NAME_LEN - 1;
              while (x >= 0 && BINLOG_NAME[x] != '/') {
                x--;
              }
              add_cluster (BINLOG_NAME, x + 1, rr, (MAIN_REPLICA ? 2 : 0) + (op == 2 ? 4 : 0) + (1 << 30));
              CC = C;
            }
          } else {
            assert (op == 3);
            char *rr = pp;
            pp = eat_not_whitespace (pp);
            char *rr_end = pp;
            pp = eat_whitespace (pp);
            *rr_end = 0;
            if (!*pp) {
              START_MANIFEST_POSITION = p + 1;
              return;
            }
            int version = atoi (pp);
            pp = eat_not_whitespace (pp);
            pp = eat_whitespace (pp);
            if (!*pp) {
              START_MANIFEST_POSITION = p + 1;
              return;
            }
            long long size = atoll (pp);
            pp = eat_not_whitespace (pp);
            pp = eat_whitespace (pp);
            if (pp == c + l && rr_end > rr && version > 0 && size >= 0) {
              struct cluster *C = CC;
              int x = BINLOG_NAME_LEN - 1;
              while (x >= 0 && BINLOG_NAME[x] != '/') {
                x --;
              }
              int rrlen = rr_end - rr;
              int i;
              for (i = 0; i < max_cluster; i++) if (Clusters[i]) {
                //fprintf (stderr, "i = %d, binlog_name = %s, rr = %s, rrlen = %d\n", i, Clusters[i]->binlog_name, rr, rrlen);
                const char *s = Clusters[i]->binlog_name;
                int l = strlen (Clusters[i]->binlog_name) - 1;
                while (l >= 0 && s[l] != '/') { l --; }
                s = s + l + 1;
                if (!memcmp (s, rr, rrlen) && s[rrlen] == '.') {
                  int old = atoi (s + rrlen + 1);
                  if (old >= version) {
                    vkprintf (0, "New version %d, old %d. Skipping\n", version, old);
                    START_MANIFEST_POSITION = p + 1;
                    return;
                  }
                  if (unlink (Clusters[i]->binlog_name) < 0) {
                    fprintf (stderr, "Can not delete old file %s: %m\n", Clusters[i]->binlog_name);
                  }
                  delete_cluster (i);
                }
              }
              static char name[1024];
              memcpy (name, rr, rrlen);
              name[rrlen] = '.';
              sprintf (name + rrlen + 1, "%06d", version);
              add_cluster (BINLOG_NAME, x + 1, name, (MAIN_REPLICA ? 2 : 0) + (1 << 30));
              LAST_SIZE = size;
              CC = C;
            }
          }
        }
      }
      START_MANIFEST_POSITION = p + 1;

    https://github.com/vk-com/kphp-kdb/blob/ce6dead5b3345f4b38487cc9e45d55ced3dd7139/copyfast/copyfast-engine.c#L1081-L1181


    Очередная порция вконтактового говнокода.

    j123123, 05 Июля 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    https://github.com/mikael-s-persson/templight
    Templight 2.0 - Template Instantiation Profiler and Debugger
    
    Templight is a Clang-based tool to profile the time and memory consumption of
    template instantiations and to perform interactive debugging sessions to gain
    introspection into the template instantiation process.

    Шаблонные метапрограммисты будут довольны.
    Осталось еще сделать такое же, но чтобы constexpr можно было профилировать и интерактивно дебажить

    j123123, 02 Июля 2018

    Комментарии (20)
  10. Си / Говнокод #24355

    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
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    // https://github.com/google/brotli/blob/29dc2cce9090d6c92c908116e11373bc7fdc8ad1/c/enc/static_dict.c#L82
    
            /* Transforms "" + BROTLI_TRANSFORM_IDENTITY + <suffix> */
            if (s[0] == ' ') {
              AddMatch(id + n, l + 1, l, matches);
              if (s[1] == 'a') {
                if (s[2] == ' ') {
                  AddMatch(id + 28 * n, l + 3, l, matches);
                } else if (s[2] == 's') {
                  if (s[3] == ' ') AddMatch(id + 46 * n, l + 4, l, matches);
                } else if (s[2] == 't') {
                  if (s[3] == ' ') AddMatch(id + 60 * n, l + 4, l, matches);
                } else if (s[2] == 'n') {
                  if (s[3] == 'd' && s[4] == ' ') {
                    AddMatch(id + 10 * n, l + 5, l, matches);
                  }
                }
              } else if (s[1] == 'b') {
                if (s[2] == 'y' && s[3] == ' ') {
                  AddMatch(id + 38 * n, l + 4, l, matches);
                }
              } else if (s[1] == 'i') {
                if (s[2] == 'n') {
                  if (s[3] == ' ') AddMatch(id + 16 * n, l + 4, l, matches);
                } else if (s[2] == 's') {
                  if (s[3] == ' ') AddMatch(id + 47 * n, l + 4, l, matches);
                }
              } else if (s[1] == 'f') {
                if (s[2] == 'o') {
                  if (s[3] == 'r' && s[4] == ' ') {
                    AddMatch(id + 25 * n, l + 5, l, matches);
                  }
                } else if (s[2] == 'r') {
                  if (s[3] == 'o' && s[4] == 'm' && s[5] == ' ') {
                    AddMatch(id + 37 * n, l + 6, l, matches);
                  }
                }
              } else if (s[1] == 'o') {
                if (s[2] == 'f') {
                  if (s[3] == ' ') AddMatch(id + 8 * n, l + 4, l, matches);
                } else if (s[2] == 'n') {
                  if (s[3] == ' ') AddMatch(id + 45 * n, l + 4, l, matches);
                }
              } else if (s[1] == 'n') {
                if (s[2] == 'o' && s[3] == 't' && s[4] == ' ') {
                  AddMatch(id + 80 * n, l + 5, l, matches);
                }
              } else if (s[1] == 't') {
                if (s[2] == 'h') {
                  if (s[3] == 'e') {
                    if (s[4] == ' ') AddMatch(id + 5 * n, l + 5, l, matches);
                  } else if (s[3] == 'a') {
                    if (s[4] == 't' && s[5] == ' ') {
                      AddMatch(id + 29 * n, l + 6, l, matches);
                    }
                  }
                } else if (s[2] == 'o') {
                  if (s[3] == ' ') AddMatch(id + 17 * n, l + 4, l, matches);
                }
              } else if (s[1] == 'w') {
                if (s[2] == 'i' && s[3] == 't' && s[4] == 'h' && s[5] == ' ') {
                  AddMatch(id + 35 * n, l + 6, l, matches);
                }
              }
            } else if (s[0] == '"') {
              AddMatch(id + 19 * n, l + 1, l, matches);
              if (s[1] == '>') {
                AddMatch(id + 21 * n, l + 2, l, matches);
              }
            } else if (s[0] == '.') {
              AddMatch(id + 20 * n, l + 1, l, matches);
              if (s[1] == ' ') {
                AddMatch(id + 31 * n, l + 2, l, matches);
                if (s[2] == 'T' && s[3] == 'h') {
                  if (s[4] == 'e') {
                    if (s[5] == ' ') AddMatch(id + 43 * n, l + 6, l, matches);
                  } else if (s[4] == 'i') {
                    if (s[5] == 's' && s[6] == ' ') {
                      AddMatch(id + 75 * n, l + 7, l, matches);
                    }
                  }
                }
              }
            } else if (s[0] == ',') {
              AddMatch(id + 76 * n, l + 1, l, matches);
              if (s[1] == ' ') {
                AddMatch(id + 14 * n, l + 2, l, matches);
              }
            } else if (s[0] == '\n') {
              AddMatch(id + 22 * n, l + 1, l, matches);
              if (s[1] == '\t') {
                AddMatch(id + 50 * n, l + 2, l, matches);
              }
            } else if (s[0] == ']') {
              AddMatch(id + 24 * n, l + 1, l, matches);
            } else if (s[0] == '\'') {
              AddMatch(id + 36 * n, l + 1, l, matches);
            } else if (s[0] == ':') {
              AddMatch(id + 51 * n, l + 1, l, matches);

    Какая-то непонятная херота из архиватора Brotli с кучей магических констант, которые хрен знает что означают. Очевидно, этот код должен находить в текстовых данных какие-то часто встречающиеся куски текста, и таким образом сжимать эту хрень (т.н. словарный метод сжатия) но зачем все так пиздануто рассовывать по буквам в куче if() ?

    Не могли для этого каких-нибудь ГОМОИКОН сделать?

    j123123, 04 Июня 2018

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

    −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
    // https://github.com/omonar/nginx-http-auth-digest/blob/38fd7eb04b862636e61b812bbbb8fd2cae4d9ab4/ngx_http_auth_digest_module.c#L910
    
            if (ngx_auth_digest_str2_casecmp(start, 'n', 'c'))
            {
                field = &ngx_http_auth_digest_fields.nc;
    
            } else if (ngx_auth_digest_str3_casecmp(start, 'q', 'o', 'p'))
            {
                field = &ngx_http_auth_digest_fields.qop;
    
            } else if (ngx_auth_digest_str3_casecmp(start, 'u', 'r', 'i'))
            {
                field = &ngx_http_auth_digest_fields.uri;
    
            } else if (ngx_auth_digest_str5_casecmp(start, 'n', 'o', 'n', 'c', 'e'))
            {
                field = &ngx_http_auth_digest_fields.nonce;
    
            } else if (ngx_auth_digest_str5_casecmp(start, 'r', 'e', 'a', 'l', 'm'))
            {
                field = &ngx_http_auth_digest_fields.realm;
    
            } else if (ngx_auth_digest_str6_casecmp(start, 'c', 'n', 'o', 'n', 'c', 'e'))
            {
                field = &ngx_http_auth_digest_fields.cnonce;
    
            } else if (ngx_auth_digest_str6_casecmp(start, 'o', 'p', 'a', 'q', 'u', 'e'))
            {
                field = &ngx_http_auth_digest_fields.opaque;
    
            } else if (ngx_auth_digest_str8_casecmp(start, 'u', 's', 'e', 'r', 'n', 'a', 'm', 'e'))
            {
                field = &ngx_http_auth_digest_fields.username;
    
            } else if (ngx_auth_digest_str8_casecmp(start, 'r', 'e', 's', 'p', 'o', 'n', 's', 'e'))
            {
                field = &ngx_http_auth_digest_fields.response;
    
            } else if (ngx_auth_digest_str9_casecmp(start, 'a', 'l', 'g', 'o', 'r', 'i', 't', 'h', 'm'))
            {
                field = &ngx_http_auth_digest_fields.algorithm;
    
            } else {
                goto skip;
    
            }

    Чем им strcasecmp не угодил?

    j123123, 29 Мая 2018

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