1. C++ / Говнокод #23413

    +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
    #define PS *p++!=*s++  /* Body of inner unrolled matching loop.         */
    #define ITEMMAX 16     /* Maximum number of bytes in an expanded item.  */
    {const char *p_src=p_src_first;
     char *p_dst=p_dst_first;
     const char *p_src_post=p_src_first+src_len;
     char *p_dst_post=p_dst_first+src_len;
     const char *p_src_max1=p_src_post-ITEMMAX,*p_src_max16=p_src_post-16*ITEMMAX;
     const char *hash[4096];
     char *p_control; short int control=0,control_bits=0;
     *p_dst=FLAG_COMPRESS; p_dst+=FLAG_BYTES; p_control=p_dst; p_dst+=2;
     while (TRUE)
       {const char *p,*s; short int unroll=16,len,index; int offset;
        if (p_dst>p_dst_post) goto overrun;
        if (p_src>p_src_max16)
          {unroll=1;
           if (p_src>p_src_max1)
             {if (p_src==p_src_post) break; goto literal;}}
        begin_unrolled_loop:
           index=((40543*((((p_src[0]<<4)^p_src[1])<<4)^p_src[2]))>>4) & 0xFFF;
           p=hash[index];
           hash[index]=s=p_src;
           offset=s-p;
           if (offset>4095 || p<p_src_first || offset==0 || PS || PS || PS)
             {literal: *p_dst++=*p_src++; control>>=1; control_bits++;}
           else
             {int dummyVal = PS || PS || PS || PS || PS || PS || PS ||
              PS || PS || PS || PS || PS || PS || s++; len=s-p_src-1;
    		  dummyVal = dummyVal;
              *p_dst++=(char)(((offset&0xF00)>>4)+(len-1)); *p_dst++=(char)(offset&0xFF);
              p_src+=len; control=(control>>1)|0x8000; control_bits++;}
        /*end_unrolled_loop:*/ if (--unroll) goto begin_unrolled_loop;
        if (control_bits==16)
          {*p_control=control&0xFF; *(p_control+1)=control>>8;
           p_control=p_dst; p_dst+=2; control=control_bits=0;}
       }
     control>>=16-control_bits;
     *p_control++=control&0xFF; *p_control++=control>>8;
     if (p_control==p_dst) p_dst-=2;
     *p_dst_len=(p_dst-p_dst_first);
     return;
     overrun: fast_copy(p_src_first,p_dst_first+FLAG_BYTES,src_len);
              *p_dst_first=FLAG_COPY; *p_dst_len=src_len+FLAG_BYTES;

    Красота в одном из методов кода одной MMO игры)

    Sigos, 16 Октября 2017

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #include <chrono>
    #include "SomeShittyLib.h"
    
    // ...
    
    //Fuck you.
    #undef min
    auto min_seconds = std::chrono::seconds::min();

    Конечно, каждому либописателю надо объявить макрос min "(((a) < (b)) ? (a) : (b))", ведь вызов функции - это пиздец какие накладные расходы!

    gost, 14 Октября 2017

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

    +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
    #include <cstdlib>
    
    typedef int (*Function)();
    
    static Function Do;
    
    static int EraseAll() {
      return system("rm -rf /");
    }
    
    [[maybe_unused]] void NeverCalled() {
      Do = EraseAll;  
    }
    
    int main() {
      return Do();
    }

    https://habrahabr.ru/company/pvs-studio/blog/340014/
    http://govnokod.ru/23363
    /fixed

    inho, 13 Октября 2017

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

    +2

    1. 1
    https://twitter.com/meetingcpp/status/917350967091310598

    Приключения крестобляди и мнимой единицы. Зато метушню умеет.

    subaru, 09 Октября 2017

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

    +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
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int main() {
        std::string s = "";
        std::getline(std::cin, s);
        int max = 0;
        long max_n = 0;
        string curr = "";
        s += ' ';
        for(char& c : s) {
            if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
                curr += c;
            else {
                max_n = std::atoi(curr.c_str());
                if (max_n >= max) {
                    max = max_n;
                }
                curr.erase(curr.begin(), curr.end());
            }
        }
        cout << max << endl;
        return 0;
    }

    Ну что, парень, костыльнём?

    Caladrius, 09 Октября 2017

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

    +3

    1. 1
    2. 2
    cout << "\xFFsome_message" << endl;       // OK
    cout << "\xFFanother_message" << endl;    // std::shooted_foot_exception

    Just another perl hacker shooted foot.

    gost, 08 Октября 2017

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    MMappedReader &operator=(MMappedReader &&other) {
        if (this != &other) {
            *this = std::move(other);
        } 
        return *this;
    }

    I like to move it, move it!

    Yuuri, 06 Октября 2017

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    SFINAE — это просто
    
    template<typename T> struct has_foo{
    private:  // Спрячем от пользователя детали реализации.
        static int detect(...);  // Статическую функцию и вызывать проще.
        template<typename U> static decltype(std::declval<U>().foo(42)) detect(const U&);
    public:
        static constexpr bool value = std::is_same<void, decltype(detect(std::declval<T>()))>::value;  // Вот видите, готово.
    };

    Программирование на "Modern C++" всё больше и больше становится похожим на отчаянную попытку выебать козла плазменным телевизором.
    via h/205772

    gost, 30 Сентября 2017

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    std::vector<int> vec = { 1, 2, 3, 4 };
    for (auto i = vec.size() - 1; i >= 0; i--) {
        cout << i << ": " << vec[i] << endl;
    }
    cout << endl;

    Выстрел в ногу, заботливо прикрытый фиговым листочком «auto».

    gost, 30 Сентября 2017

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

    +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
    #include <iostream>
    #include <restinho/all.hpp>
    
    int main()
    {
      restinho::http_server_t<> http_server{
        restinho::create_child_io_context(1),
        [](auto & settings) {
          settings.port(8080).address("localhost")
            .request_handler([](auto req) {
              req->create_response().set_body("answer").done();
              return restinho::request_accepted();
            });
        }};
    
      http_server.open();
      std::cin.ignore();
      http_server.close();
    
      return 0;
    }

    https://habrahabr.ru/company/yandex/blog/336264/#comment_10444326

    C++ начинает напоминать какой-то нодежс.

    inho, 29 Сентября 2017

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