1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #172

    +11.9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if ($site_is_work)
     {
     }
    else
     {
    	exit('Сайт не работает');
     }

    guest, 14 Декабря 2008

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

    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
    // https://github.com/dotnet/runtime/issues/117233#issuecomment-3028066225
    
    // Issue: Math.Pow relies directly on the OS pow implementation
    
    // Location: [src/coreclr/classlibnative/float/floatdouble.cpp lines 232‑236] and [src/coreclr/classlibnative/float/floatsingle.cpp lines 207‑211]
    
    // COMDouble::Pow and COMSingle::Pow simply call pow/powf from the C runtime. On Windows 11 Insider Preview (build 27881.1000),
    // these functions can return incorrect results (e.g., Math.Pow(-1, 2) giving -1). The JIT also uses these functions for constant folding, causing
    // wrong constants to be embedded at compile time.
    
    // Suggested Fix: Introduce a managed fallback in COMDouble::Pow/COMSingle::Pow that handles negative bases with integral exponents, bypassing the faulty system call.
    
    //A simple approach:
    
    FCIMPL2_VV(double, COMDouble::Pow, double x, double y)
    {
        FCALL_CONTRACT;
    
        if ((x < 0.0) && (y == floor(y)))
        {
            double absResult = pow(-x, y);
            return fmod(fabs(y), 2.0) == 1.0 ? -absResult : absResult;
        }
    
        return pow(x, y);
    }
    
    // Suggested Implementation:
    
    // Add the following code to src/coreclr/classlibnative/float/floatdouble.cpp below line 234 before the return pow:
    
    if ((x < 0.0) && (y == floor(y)))
    {
        double result = pow(-x, y);
    
        if (fmod(fabs(y), 2.0) != 0.0)
        {
            result = -result;
        }
    
        return result;
    }
    
    // Add the following code to src/coreclr/classlibnative/float/floatsingle.cpp below line 209 before the return powf:
    
    if ((x < 0.0f) && (y == floorf(y)))
    {
        float result = powf(-x, y);
    
        if (fmodf(fabsf(y), 2.0f) != 0.0f)
        {
            result = -result;
        }
    
        return result;
    }
    
    // Add the following code to src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Math.cs below line 1124:
    
    [Fact]
    public static void Pow_NegativeBaseEvenExponent_ReturnsPositive()
    {
        Assert.Equal(1.0, Math.Pow(-1, 2));
        Assert.Equal(16.0, Math.Pow(-2, 4));
    }

    Вот к чему плавучий петух приводит!

    j123123, 04 Июля 2025

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

    +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
    /* Python:
    
    def A004086(n):
    return int(str(n)[::-1])
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int A004086(int n) {
        char str[12]; // Enough to hold the string representation of an int
        sprintf(str, "%d", n);
        int len = strlen(str);
        char reversed[12];
        
        for (int i = 0; i < len; i++) {
            reversed[i] = str[len - 1 - i];
        }
        reversed[len] = '\0'; // Null-terminate the string
        
        return atoi(reversed);
    }

    Результат переписывание с "Python" на "C". A004086 это последовательность из OEIS https://oeis.org/A004086

    j123123, 02 Января 2025

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

    0

    1. 1
    $_GET

    OCETuHCKuu_nemyx, 15 Октября 2024

    Комментарии (22)
  6. Java / Говнокод #28592

    −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
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    import java.io.IOException;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.util.Scanner;
    import java.util.zip.*;
    import java.io.*;
     
    public class CitiesPrinter {
     
        public static void main(String[] args) throws IOException {
           
            final String fileName = "/storage/emulated/0/Documents/Jvdroid/single-files/_данные_Сбер_Java_20210407090226.zip";
            try(ZipInputStream unzipping = new ZipInputStream(new FileInputStream(fileName)));
           {
             ZipEntry entry = null;
            String name = null;
            long size = 0;
            
            while((entry=unzipping.getNextEntry())!= null) {
            name = entry.getName();
            size = entry.getSize();
            System.out.println("FileName: " + name + "FileSize: " + size);
            FileOutputStream unzippedFile = new FileOutputStream("/storage/emulated/0/Documents/Jvdroid/single-files/new" + name);
                    for (int c = unzipping.read(); c != -1; c = unzipping.read()) {
                        unzippedFile.write(c);
                    }
                    unzippedFile.flush();
                    unzipping.closeEntry();
                    unzippedFile.close();
            }
           }
           catch(Exception e){
            System.out.println(e.getMessage());
           }
            
            Path path = Paths.get(fileName);
            Scanner scanner = new Scanner(path);
             
            
            scanner.useDelimiter(System.getProperty("line.separator"));
            while(scanner.hasNext()){
                System.out.println("Строка: " + scanner.next());
            }
            scanner.close();
            
            scanner = new Scanner(Paths.get("/storage/emulated/0/Documents/Jvdroid/single-files/_данные_Сбер_Java_20210407090226.zip/city_ru.csv"));
            scanner.useDelimiter(System.getProperty("line.separator"));
            while(scanner.hasNext()){
                
                Employee emp = parseCSVLine(scanner.next());
                System.out.println(emp.toString());
            }
            scanner.close();
             
            
            scanner = new Scanner(System.in);
            System.out.println("Вводим первое слово: " + scanner.next());
        }
    
         
        private static Employee parseCSVLine(String line) {
             Scanner scanner = new Scanner(line);
             scanner.useDelimiter("\\s*,\\s*");
             String name = scanner.next();
             int age = scanner.nextInt();
             String gender = scanner.next();
             CitiesPrinter jfs = new CitiesPrinter();
             return jfs.new Employee(name, age, gender);
        }
    }
     
        class Employee{
            private String name;
            private int age;
            private String gender;
             
            public Employee(String n, int a, String gen){
                this.name = n;
                this.age = a;
                this.gender = gen;
            }
             
            @Override
            public String toString(){
                return "Name=" + this.name + "::Age=" + this.age + "::Gender=" + this.gender;
            }
        }

    Что не так?

    sbnet, 09 Февраля 2023

    Комментарии (22)
  7. JavaScript / Говнокод #28502

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    const newRecords = {}
    
    for (const prop in overridenRecords) {
      if(Object.prototype.hasOwnProperty.call(overridenRecords, prop)) {
        const source = Object.values(allRecords).find((record) => record.id == prop)
        newRecords[prop] = {...overridenRecords[prop], ...source}
      }
    }
    
    return newRecords

    bootcamp_dropout, 17 Декабря 2022

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

    +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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    // Heap memory allocate function (must not be used!)
    caddr_t _sbrk(int incr) {
        <...>
        void some_bastard_called_sbrk();
        some_bastard_called_sbrk(); // Produce linker error in case it is used
    }
    
    _ATTRIBUTE ((__format__ (__printf__, 1, 2)))
    int	printf (const char *__restrict format, ...)
    {
        <маленький трехколесный велосипед>
    }
    
    int	putchar(int c) 
    {
        <...> 
    }
    int	puts(const char *s) 
    {
        <...> 
    }
    
    _ATTRIBUTE ((__format__ (__printf__, 2, 3)))
    int	sprintf (char *__restrict s, const char *__restrict format, ...)
    {
        <...> 
    }

    STM32. Я просто хочу использовать printf для вывода в последовательный порт и не течь. Ведь для этого нужно только реализовать int _write(int file, char *data, int len) и всё. Ой, а почему иногда программа падает где-то в кишках рантайма?

    Может, стек переполняется? Да нет, проверил, значения в норме...

    Просто стандартная библиотека от ST - это не курсовая ардуинщика, тут все системно, хендлы потоков, дескрипторы устройств и управляющие структуры. При первом обращении printf (и sprintf тоже!) выделяет себе в куче около 400 байт. Замечательное решение, помогающее сэкономить память, если мы не используем стандартный вывод! А куча тут - это просто последовательно заполняемая область памяти, размеры которой задаются в linker script (я вообще 0 указал, я ведь не использую malloc). Проверять выход за пределы кучи мы, конечно, не будем - зачем, когда рядом такая замечательная, никому не нужная область стека.
    Да, и если забыть отключить буферизацию setvbuf(stdin/stdout/stderr, NULL, _IONBF, 0); , то он выделит не 400 байт, а килобайт (на контроллере с 8K RAM).

    В общем, ах, оставьте меня, сам все напишу.
    Только надо еще putchar и puts реализовать, а то компилятор любит printf'ы оптимизировать. И не забыть, что puts добавляет перевод строки. Уф, вроде все.

    Steve_Brown, 05 Августа 2022

    Комментарии (22)
  9. 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)
  10. Куча / Говнокод #28101

    0

    1. 1
    Борманд, у тебя спина рыжая!

    Ха-ха, я пошутил, с первым апреля )))

    JloJle4Ka, 01 Апреля 2022

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

    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
    #define CONSTRUCT_JUMP(name_, opcode_) else if(mnemonic.name == #name_) \
    	subcompileMnemonic(mnemonic, {\
    	{constructDescription(CONSTANT), opcode_},\
    	{constructDescription(LABEL), opcode_}})
    
    	CONSTRUCT_JUMP(JMP, JMP);
    
    	CONSTRUCT_JUMP(JE, JZ);
    	CONSTRUCT_JUMP(JZ, JZ);
    
    	CONSTRUCT_JUMP(JNZ, JNZ);
    	CONSTRUCT_JUMP(JNE, JNZ);
    
    	CONSTRUCT_JUMP(JG, JG);
    	CONSTRUCT_JUMP(JNLE, JG);
    	CONSTRUCT_JUMP(JNLZ, JG);
    
    	CONSTRUCT_JUMP(JLE, JNG);
    	CONSTRUCT_JUMP(JLZ, JNG);
    	CONSTRUCT_JUMP(JNG, JNG);
    
    	CONSTRUCT_JUMP(JGE, JGZ);
    	CONSTRUCT_JUMP(JGZ, JGZ);
    	CONSTRUCT_JUMP(JNL, JGZ);
    
    	CONSTRUCT_JUMP(JNGZ, JL);
    	CONSTRUCT_JUMP(JNGE, JL);
    	CONSTRUCT_JUMP(JL  , JL);
    
    	CONSTRUCT_JUMP(JB, JB);
    	CONSTRUCT_JUMP(JNAE, JB);
    	CONSTRUCT_JUMP(JNAZ, JB);
    	CONSTRUCT_JUMP(JC, JB);
    
    	CONSTRUCT_JUMP(JNB, JNB);
    	CONSTRUCT_JUMP(JAE, JNB);
    	CONSTRUCT_JUMP(JAZ, JNB);
    	CONSTRUCT_JUMP(JNC, JNB);
    
    	CONSTRUCT_JUMP(JBE, JBZ);
    	CONSTRUCT_JUMP(JBZ, JBZ);
    	CONSTRUCT_JUMP(JNA, JBZ);
    
    	CONSTRUCT_JUMP(JA, JA);
    	CONSTRUCT_JUMP(JNBE, JA);
    	CONSTRUCT_JUMP(JNBZ, JA);
    
    	CONSTRUCT_JUMP(CALL, CALL);
    #undef CONSTRUCT_JUMP

    kcalbCube, 01 Марта 2022

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