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

    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
    #include <stdio.h>
    
    struct{int a; float b;} test()
    {
      return (typeof(test())){1337, 666.666};
    }
    
    int main()
    {
      auto a = test();
      printf("%d %f\n", a.a, a.b);
      return 0;
    }

    В стандарт C23 добавили auto и теперь можно писать такую хуйню. В "Clang" работает: https://godbolt.org/z/GG3addqPb

    j123123, 17 Июня 2025

    Комментарии (47)
  2. Си / Говнокод #29130

    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
    #include <stdio.h>
    
    int bts(unsigned int n, int bitN) {
        return n & (1 << bitN);
    }
    
    int main() {
        volatile char *p_lacoon;
        unsigned char res = 0;
        
        p_lacoon = ((unsigned )p_lacoon | 01 << 1);
        res |= bts(p_lacoon, 0) | bts(p_lacoon, 1);
    
        p_lacoon = ((unsigned )p_lacoon | 01 & ~!~0);
        p_lacoon = ((unsigned )p_lacoon | 01 << 1 << 0);
        res |= 4 << (bts(p_lacoon, 0) | bts(p_lacoon, 1) ^ 3);
    
        p_lacoon = ((int)p_lacoon | 01 & ~0xFE | 00);
        p_lacoon = ((int)p_lacoon | 01 << 1);
        res |= ~!0xFF << (bts(p_lacoon, 0) | 6 ^ 0x29b);
        res |= ~!0xFC << (bts(p_lacoon, 1) | 4 ^ 0x29c);
        res |= ~!0xF0 << 5;
    
        p_lacoon = (int)p_lacoon >> 01 >> 001 << 001 << 01;
    
        printf("%x, %X %s\n", p_lacoon, (res & 001) ? res-1 : res, "*****. Challenge everything.");
    }

    Предтерминальная стадия мозгфускации.
    Из собеса в подразделение AMD: продемонстрировать варианты хранения при недостатке памяти.
    Работает в GCC, ICC, Clang только -O0.
    Кто хочет разобраться - welcome https://godbolt.org/z/hd4eYeM1Y

    OdduOne, 09 Мая 2025

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

    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
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <limits.h>
    
    int gcc_rtm_virt_test(int a, int(*f)(int, int(*)(), float*), float fa[static (-1,0,1)]) {
        short s = sizeof (short) + sizeof 0;
        char b[12] = "0123456789";
    
        for (long ll = sizeof b; ll -= 4;) {
            b[ll]   = '0';
            b[ll-1] = '1';
            b[ll-2] = '2';
            b[ll-3] = '3';
        }
    
        return s - ((1 << 2) - (b[0] - '2'));
    }
    
    int gcc_rtm_cf32(int(*f0)(), int(*f1)()) {
        ptrdiff_t d = f1 - f0;
        // guess you know what you're doing
        if (! (d >> sizeof (ptrdiff_t) * CHAR_BIT - 1)) { 
            while (d--) {
                switch(*(unsigned short*)(f0 + d)) {
                    case 0xc3c9:
                        return 0;
                    case 0xb8:
                        if (!*(unsigned int*)(f0 + d + 1)) {
                            return 1;
                        } 
                        break;
                    case 0xC031:
                        return 2;
                }
            }
            return -1;
        };
    
        return -2;
    }
    
    int main() {
    
        switch (gcc_rtm_cf32(gcc_rtm_virt_test, gcc_rtm_cf32)) {
            case -1:
                fprintf(stderr, "Hey, added smth. special? Maybe -Og? \n"), abort();
                break;
            case 0:
                fprintf(stderr, "Hey, -O0 smells like a dead rat.. check your flags!\n"), abort();
                break;
            case 1:
                fprintf(stderr, "Hey, -O1 is still not allowed.. Would you do better?\n"), abort();
                break;
            case 2:
                fprintf(stdout, "Hey, finally you've captured [-O2 || -O3 || -Ofast || -Os] flag!");
                break;
            default:
                fprintf(stderr, "Hey, looks like you've got impl. defined crap, check PTRDIFF_T stuff.. \n"), abort();
                break;
        };
    
    }

    И далее по тексту..gcc'шники опять обкурились в рантайме. Зачэм так делоть, это прикольно?

    BCHARa, 10 Апреля 2025

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

    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
    void rtm_guard(void) {
        /*
            Don't even try to MS VC that stuff, zerobuffy 4eyes.
        */
        unsigned char buf0[0];
        unsigned a = 0xF001BA11;
        unsigned b = 0xF001BA11;
        unsigned c = 0x55550000;
        unsigned d = 0xF001BA11;
        unsigned e = 0xF001BA11;
        unsigned char buf1[0];
        ptrdiff_t diff = buf0 - buf1;
    
        const char* prnt;
        switch (diff) {
            case sizeof rtm_guard:
                prnt = "dear Nizhny Novgorod '-O1' lover";
                break;
            case sizeof (int):
                prnt = "'gcc -O0' bastard";
                break;
            default:
                prnt = "\b";
        };
    
        (diff == sizeof (int) || diff == sizeof rtm_guard) ?
        fprintf(stderr, "%s%s%s", 
                    "Hey you, ", prnt, ", what the hell are you trying to bang here w/o mandatory flags? Forgot something? \n"), abort() : 
        0;
    }

    Сodebomb в рантайме наложил. Но нафига? Присосаться хуком и послать курить джуника с лидом как рукопожато билдить?

    BCHARa, 08 Апреля 2025

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

    0

    1. 1
    #include <console_io.h>

    конио

    3_dar, 03 Апреля 2025

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

    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
    // https://tio.run/##jY9PC4JAFMTv@ymGJHFjDc06WUEdugpd1YPomgu2in8oED@7WVpRh@jdZt7vDfNCPUwDeeo6oggZpnXEsS6rSGTzZEuIEvFYSI6D42g5QxbHJa8oogwNPIJ@8kLIKtYm06snJwxq7uoD5VO7R1pcEpFyzaDvsP3u@F/YjyzSgzgHQmoUzeP2bgSujw0ag8FkWDBYDEuGVWu/iFneA2rgWv7gjY@Z9FPWox6rml/yuS54VRcShk3arrsB
    
    #include <stdio.h>
    
    #define FOO(p, offset) do { \
        printf("%x\n", &p[-offset]); \
    } while(0)
    
    #define BAR(p, offset) do { \
        printf("%x\n", p[-offset]); \
    } while(0)
    
    
    int main() {
        int a[] = {0, 1, 2, 3, 4, 5};
        int *p = &a[3];
        FOO(p, 1);
        FOO(p, 1u);
        BAR(p, 1);
        BAR(p, 1u);
        return 0;
    }

    testhuest, 27 Марта 2025

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

    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
    typedef struct ll_node
    {
      struct ll_node *prev;
      struct ll_node *next;
      int val;
    } ll_node;
    
    ll_node a;
    ll_node b;
    ll_node c = {&a, &b,3};
    
    // не работает
    a.next = &b;
    a.prev = &c;
    
    b.next = &c;
    b.prev = &a;
    
    /*
    c.next = &a;
    c.prev = &b;
    */
    
    // зато так работает:
    ll_node arr[3] = {
      {&arr[2], &arr[1],1},
      {&arr[0], &arr[2],2},
      {&arr[1], &arr[0],3}
    };

    Кольцевой двусвязный список.

    j123123, 10 Марта 2025

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

    +1

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

    К нему возвращаются опять и опять, и, что удивительно, тем чаще, чем язык высокоуровневей.

    Напоминает попытки быдла бросить курить.

    KPblCA, 08 Марта 2025

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

    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
    // https://godbolt.org/z/f4s13WEWM
    
    #include <inttypes.h>
    
    int test(uint32_t a, uint32_t b)
    {
      if (a > b)
        return a+b;
      return a*b;
    }
    
    int test2(uint32_t a, uint32_t b)
    {
      return (a+b)*(a > b) | (a*b)*!(a > b);
    }
    
    int test3(uint32_t a, uint32_t b)
    {
      return
        ((a+b) & (uint32_t)(!(a > b) - 1)) |
        ((a*b) & (uint32_t)((a > b) - 1));
    }
    
    int test4(uint32_t a, uint32_t b)
    {
      const uint32_t arr[2] = {a+b, a*b};
      return arr[!(a > b)];
    }
    
    /* ASM output
    test:
            bltu    a1, a0, .LBB0_2
            mul     a0, a1, a0
            ret
    .LBB0_2:
            add     a0, a0, a1
            ret
    
    test2:
            bltu    a1, a0, .LBB1_2
            mul     a0, a1, a0
            ret
    .LBB1_2:
            add     a0, a0, a1
            ret
    
    test3:
            bltu    a1, a0, .LBB2_2
            mul     a0, a1, a0
            ret
    .LBB2_2:
            add     a0, a0, a1
            ret
    
    test4:
            addi    sp, sp, -16
            add     a2, a1, a0
            mul     a3, a1, a0
            sltu    a0, a1, a0
            sw      a2, 8(sp)
            sw      a3, 12(sp)
            xori    a0, a0, 1
            slli    a0, a0, 2
            addi    a1, sp, 8
            add     a0, a0, a1
            lw      a0, 0(a0)
            addi    sp, sp, 16
            ret
    */

    Наглядная демонстрация того, что компилятор может насрать на ваши попытки заставить его сгенерить branchless машинный код. Получилось это только в "test4"

    j123123, 07 Марта 2025

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

    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
    extern char* strcat( char* dest, const char* src );
    extern int   printf ( const char * restrict format, ... );
    extern int   putchar( int ch );
    
    #define LISPER(n, l, re) ({                                                                                                     \
                    auto int ii = l;                                                                                                          \
                    static unsigned char n[l];                                                                                      \                           
                    while (ii--) {                                                                                                             \
                        *str##n(n, (unsigned char[]){0x09 >> 1 << 1, 0x1911 >> 0xD});                \
                    };                                                                                                                               \
                    *((void**)&re) = printf((unsigned char[]){0x25, 0x73, 0x1917 >> 0xE}, n); \
                    })
    
    struct bombitterLemon{
        union {
            unsigned char   : 0;
            unsigned char   : 0;
            unsigned char v: 7;
        } pacific;
    };
    
    int main(void) {
    
        struct bombitterLemon b0; 
    
        LISPER(cat, 0x40 ^ (2 << 2), b0);
        (*putchar) (*(struct wtf**)&b0);
        LISPER(cat, ((int) (((char*)   (0x8 ^ (1 << 6))) - 3) | 1), b0);
        (**putchar) (*(struct is***)&b0);
        LISPER(cat, ((int) (((short*)  (0x9 << 3))) | 4), b0);
        (***putchar) (*(struct that****)&b0);
        LISPER(cat, ((int) (((int*)    (0x12 << 2))) | 4), b0);
        (**putchar) (*(unsigned char*****)&b0);
        LISPER(cat, ((int) (((long*)   (0x90 >> 1))) | 4 | 2 | 1), b0);
        (*putchar) (b0.pacific.v);
    
    }

    Классический собесный говнокод для кунов на громкие позиции malware ANALyst, security дрист-searcher и даже (о, ужас) compiler devteam в известные шарашки.
    Шланг<15 и ICC жуют с говном не глядя. Чего не сказать о бычаре, дристающего на коврик.
    Осилил, анонимус? Поясни пацанам на пальцах за высер без единого include с ноября прошлого.

    Dulldonch1k, 13 Февраля 2025

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