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

    Всего: 16

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

    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
    auto objs = it.get_objects();
    
                switch(objs.size())
                {
                    case 1:     sent = _out_stream.send_message(objs[0]);
                                break;
                    case 2:     sent = _out_stream.send_message(objs[0], objs[1]);
                                break;
                    case 3:     sent = _out_stream.send_message(objs[0], objs[1], objs[2]);
                                break;
                    case 4:     sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3]);
                                break;
                    case 5:     sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4]);
                                break;
                    case 6:     sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5]);
                                break;
                    case 7:     sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6]);
                                break;
                    case 8:     sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7]);
                                break;
                    case 9:     sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8]);
                                break;
                    case 10:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9]);
                                break;
                    case 11:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10]);
                                break;
                    case 12:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11]);
                                break;
                    case 13:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12]);
                                break;
                    case 14:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13]);
                                break;
                    case 15:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13], objs[14]);
                                break;
                    case 16:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13], objs[14], objs[15]);
                                break;
                    case 17:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13], objs[14], objs[15], objs[16]);
                                break;
                    case 18:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13], objs[14], objs[15], objs[16], objs[17]);
                                break;
                    case 19:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13], objs[14], objs[15], objs[16], objs[17],
                                                                objs[18]);
                                break;
                    case 20:    sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
                                                                objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
                                                                objs[12], objs[13], objs[14], objs[15], objs[16], objs[17],
                                                                objs[18], objs[19]);
                                break;
                    default:
                        fprintf(stderr, "error: Too much attached objects (%lu), talk to developer\n", objs.size());
                        return false;
                }
    
                if (!sent)
                {
                    fprintf(stderr, "error: Unable to send message to output pipe\n");
                    return false;
                }

    Меня заставили это сделать, потому что по задумке число вложенных объектов известно на этапе разработки, а у меня - нет.

    YpaHeLI_, 31 Августа 2023

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

    +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
    while (!cmpts.empty() && !ec)
        {
          path f = std::move(cmpts.front());
          cmpts.pop_front();
    
          if (f.empty())
    	{
    	  // ignore empty element
    	}
          else if (is_dot(f))
    	{
    	  if (!is_directory(result, ec) && !ec)
    	    ec.assign(ENOTDIR, std::generic_category());
    	}
          else if (is_dotdot(f))
    	{
    	  auto parent = result.parent_path();
    	  if (parent.empty())
    	    result = pa.root_path();
    	  else
    	    result.swap(parent);
    	}
          else
    	{
    	  result /= f;
    
    	  if (is_symlink(result, ec))
    	    {
    	      path link = read_symlink(result, ec);
    	      if (!ec)
    		{
    		  if (--max_allowed_symlinks == 0)
    		    ec.assign(ELOOP, std::generic_category());
    		  else
    		    {
    		      if (link.is_absolute())
    			{
    			  result = link.root_path();
    			  link = link.relative_path();
    			}
    		      else
    			result = result.parent_path();
    
    		      cmpts.insert(cmpts.begin(), link.begin(), link.end());
    		    }
    		}
    	    }
    	}
        }

    Это из GNU libstdc++.
    Код то может и не говно, но от форматирования блевать тянет.
    Зачем такое кто знает?

    YpaHeLI_, 06 Марта 2023

    Комментарии (14)
  4. Куча / Говнокод #28456

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Решил поставить пароль на BIOS (UEFI), но и он, оказывается, не панацея.
    Если ты параноик, то просто таскай ноутбук с собой, а вот если у тебя системник - смирись, за тобой могут следить.
    
    https://techarks.ru/windows/bios/kak-vosstanovit-ili-ustanovit-parol-bios-ili-uefi-dlya-kompyuterov-s-windows/
    https://habr.com/ru/post/128466/

    YpaHeLI_, 24 Ноября 2022

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

    −3

    1. 1
    Ну и как вы стали сеньорами? Делитесь опытом.

    YpaHeLI_, 06 Октября 2022

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

    −4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    На работе такая таска:
    Есть сервис, который запускает наши сервисы и следит за ними, напр. перезапускает, если один из них упал.
    Таска такая, что нужно посылать всем сервисам сообщения из командной строки.
    Т.е. уже можно послать сигналы из командной строки (SIGTERM, SIGHUP, и.т.д)
    `svctl -s stop` - наример.
    Но теперь нужно посылать SIGUSR1, перед этим записав в файл сообщение, тоже переданное из командной строки. Все запущенные сервисы по этому сигналу должны прочитать файл с сообщением и обработать его.
    И вот тут я сомневаюсь, что так правильно.
    1. Может лучше открыть именованный канал, и туда всё посылать, без сигналов? Но тут треды и код усложнится, а проект простой, на 20 методов в двух классах.
    2. Если это всё же правильно, то вместо файла тоже может использовать именованный канал для обмена сообщениями?

    YpaHeLI_, 19 Сентября 2022

    Комментарии (16)
  7. PHP / Говнокод #28102

    +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
    <?php defined('SYSPATH') or die('No direct script access.');
    /*
     * Базовый класс главной страницы
     */
    class Controller_Index extends Controller {
    
    
            public function before() {
                    parent::before();
                    I18n::lang('ru');
                    $settings = Kohana::config('settings');
                    Cookie::$salt = 'asd12d2';
                    Session::$default = 'cookie';
                    $this->session = Session::instance();
            }
    
        public function action_index() {
    
            //Путь до файла первоночального xml (xsl)
            $path_xml='tpl/xml.xsl';
            //Путь конечного xsl
            $path_xsl='tpl/index.xsl';
    
            $url = $this->request->param('stuff');
                    //print_r($_SERVER);
                    /*if($_SERVER ['REQUEST_URI']=='/'){
                            $this->request->redirect($_SERVER ['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_HOST'],'301');
                    }*/
            if(empty($url)){
                $url='/';
            }
    
    
            $htmlfile='cache-html/'.md5($url);
    $allurl=$_SERVER ['REQUEST_URI'];
    if($allurl=='/20-40-kvm') $this->request->redirect('/sadovye-domiki','301');
    if($allurl=='/40-80-kvm') $this->request->redirect('/sadovye-domiki','301');
    if($allurl=='/80-i-bolee-kvm') $this->request->redirect('/sadovye-domiki','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=0&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/sadovye-domiki','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=1&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=81-400') $this->request->redirect('/80-i-bolee-kvm','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=1&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=40-80') $this->request->redirect('/40-80-kvm','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/stroitelstvo-dachnyh-domov','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=2&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&technology%5B%5D=3&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/kottedzhi','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=0&technology%5B%5D=2&technology%5B%5D=3&floors%5B%5D=1&floors%5B%5D=1.5&price=0-3000000&area=0-400') $this->request->redirect('/bani','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&price=0-3000000&area=0-400') $this->request->redirect('/bani-iz-profilirovannogo-brusa','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=0&floors%5B%5D=1&floors%5B%5D=1.5&price=0-3000000&area=0-400') $this->request->redirect('/karkasnye-bani','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=3&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/bani-iz-ocilindrovannogo-brevna','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=316018-3000000&area=0-400') $this->request->redirect('/brus','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/kottedzhi-profilirovannyj-brus','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=0&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=329056-3000000&area=0-400') $this->request->redirect('/dachnye-doma-karkasnaya-tehnologiya','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=1&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/individualnye-proekty','301');

    Там ещё дальше веселье продолжается, но гк не дает запостить больше

    YpaHeLI_, 02 Апреля 2022

    Комментарии (22)
  8. PHP / Говнокод #27898

    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
    function normalizeUrl($url)
    {
        if (strpos($url, 'http://') === 0) {  
             $domain = substr($url, 7);
         } elseif (strpos($url, 'https://') === 0) {
              $domain = substr($url, 8);
         } else {
              $domain = $url;
         }
    
         return "https://{$domain}";
    }

    YpaHeLI_, 27 Декабря 2021

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

    +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
    struct file_id
    {
        uint64_t        persistent;
        uint64_t        volatile_;
    
        static const size_t RAW_LENGTH  = 16;
        operator std::string() const
        { return std::string(reinterpret_cast<const char*>(&persistent), RAW_LENGTH); }
    
        // Операторы для использования file_id в качестве ключа map и 
        // unordered_map
        struct hash
        {
            std::size_t operator()(const ntdec_smb2_file_id& file_id) const
            {
                std::string s_file_id = file_id;
                std::hash<std::string> hasher;
                return hasher(s_file_id);
            }
        };
    
        bool operator == (const ntdec_smb2_file_id& other)
        {
            return std::string(*this) == std::string(other);
        }
    
        bool operator < (const ntdec_smb2_file_id& other)
        {
            return std::string(*this) < std::string(other);
        }
    
        bool operator > (const ntdec_smb2_file_id& other)
        {
            return std::string(*this) > std::string(other);
        }
    };

    operator std::string тоже UB?

    YpaHeLI_, 24 Августа 2021

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #include <iostream>
    #include <map>
    
    int main()
    {
      std::string name;
      std::map<int, int> m = { {1, 1}, {2, 2} };
      m.erase(m.end());
      std::cout << "Kokoko " << m[1] << std::endl;
    }

    На моем проекте уходит в бесконечный цикл.

    YpaHeLI_, 08 Июня 2021

    Комментарии (58)
  11. C++ / Говнокод #27423

    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
    // Приведение численного типа к структуре с битовыми полями
    template <class STRUCT_T, typename T>
    STRUCT_T struct_cast(const T n)
    {
        static_assert(std::is_integral<T>::value, "Integral type required as T");
        static_assert(std::is_class<STRUCT_T>::value, "class or struct type required as STRUCT_T");
        static_assert(sizeof(T) == sizeof(STRUCT_T), "Incompatible types passed");
    
        return *(reinterpret_cast<const STRUCT_T*>(&n));
    }
    
    // Приведение структур с битовыми полями к численному типу
    template <typename T, class STRUCT_T>
    T integral_cast(const STRUCT_T& s)
    {
        static_assert(std::is_integral<T>::value, "Integral type required as T");
        static_assert(std::is_class<STRUCT_T>::value, "class or struct type required as STRUCT_T");
        static_assert(sizeof(T) == sizeof(STRUCT_T), "Incompatible types passed");
    
        return *(reinterpret_cast<const T*>(&s));
    }

    Почему это UB?

    YpaHeLI_, 12 Мая 2021

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