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

    +148

    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
    bsz = (bsz + 3) & ~3L;
    
      tp->beg = alloc_malloc(bsz, tp->almark);
      tp->end = tp->beg + bsz;
      tp->cur = tp->beg;
      tp->aux = tp->beg;
    
      tp->mode = TAPE_MODE_IDLE;
      tp->err = FAKE_OK;
    
      tp->drv = drv;
      tp->info = NULL;
    
      ret = tp->drv->init(tp, argv);
    
      if (ret == FAKE_FAIL) {
        alloc_free_by_mark(almark);

    http://www.gamedev.ru/flame/forum/?id=153724&page=13#m190

    AnimeGovno-_-, 26 Октября 2011

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

    +145

    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
    int nSymb;
    char pCh[32];
    char tbldec[] = "0123456789000000";
    char tblhex[] = "0123456789ABCDEF";
    
    void MyDWtoStr(DWORD dw)
    {
      __asm
      {
        mov eax,dw
        test eax,eax
        jnz short lab1
        mov esi,1//esi = nSymb = 1
        mov byte ptr [pCh],30h
        jmp short lab2
    lab1:
        mov ebx,eax
        mov ecx,eax//eax = ebx = ecx = dw
        xor esi,esi//esi = nSymb = 0
    lab4:
        mov eax,ecx//eax=ecx=b
        mov ebx,0Ah//ebx=10
        xor edx,edx
        div ebx
        mov ebx,edx//ebx=a=b%10
        mov al,[tbldec+ebx]
        mov [pCh+esi],al//pCh[nSymb]=tbldec[a]
        inc esi//nSymb++
        mov eax,ecx
        sub eax,ebx//eax=b-a
        mov ecx,0Ah
        xor edx,edx
        div ecx
        mov ecx,eax//ecx=b=(b - a)/10;
        test ecx,ecx
        jnz short lab4
    
        mov eax,esi
        dec eax//eax = i = nSymb-1
        jmp short lab5
    lab6:
        mov edx,esi//edx = nSymb
        sub edx,eax//edx = nSymb-i
        mov bl,[edx+pCh-1]//bl = pCh[nSymb-i-1];
        mov cl,[eax+pCh]
        mov [edx+pCh-1],cl//pCh[nSymb-i-1]=pCh[i];
        mov [eax+pCh],bl//pCh[i]=pCh[nSymb];
        dec eax
    lab5:
        mov ecx,eax
        shl ecx,1//add ecx,ecx
        cmp ecx,esi
        jge short lab6
    lab2:
        mov dword ptr [nSymb],esi
        mov byte ptr [esi+pCh],0
      }
    }
    
    DWORD MyStrtoDW(char *pch)
    {
      DWORD a;
      __asm
      {
        mov edi,pch
        xor eax,eax//eax = a
        xor esi,esi//esi = i
        mov ecx,10
        jmp short lab2
    lab1:
        mul ecx
        and ebx,0FFh
        sub ebx,48
        add eax,ebx
        inc esi
    lab2:
        mov bl,byte ptr [edi+esi]
        test bl,bl
        jnz short lab1
        mov a,eax
      }
      return a;
    }

    >Хочу представить вашему вниманию очень быстрые функции для преобразований DWORD <---> char [].

    http://www.gamedev.ru/flame/forum/?id=153979

    AnimeGovno-_-, 25 Октября 2011

    Комментарии (28)
  3. JavaScript / Говнокод #8294

    +155

    1. 1
    2. 2
    3. 3
    $(".rent_table._rent_list tbody input").each(function() {
                            $(this).attr("checked", "checked");
     });

    $(".rent_table._rent_list tbody input"). attr("checked", "checked");

    PEOPLE WHY Y NO RTFM?

    PS этот each отрабатывался на сотне inputов, чем вешал ie6

    Kakashulenka, 25 Октября 2011

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

    +161

    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
    QString str[5][5] = {"a", "b", "c", "d", "e",
                             "f", "g", "h", "i", "k",
                             "l", "m", "n", "o", "p",
                             "q", "r", "s", "t", "u",
                             "v", "w", "x", "y", "z"};
        QString enc, text = ui->lineEdit->text();
        int l = text.length();
        QString tmp[1][8] = {"s", "o", "m", "e", "t", "e", "x", "t"};
        for (int i = 0; i < 1; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                for (int ix = 0; ix < 6; ix++)
                {
                    for (int jx = 0; jx < 6; jx++)
                    {
                        if(tmp[i][j] == str[ix][jx])
                            enc = str[ix][jx + 1];
                        ui->lineEdit_2->setText(enc);
                    }
                }
            }
        }
    }

    Такой-то квадрат Полибия!

    Mindless, 25 Октября 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    QT project:
    
    t=x1; x1=x2; x2=t;
    t=y1; x1=y2; y2=t;

    И еще 90 говнопятнышек!
    Налетай: http://www.viva64.com/ru/a/0077/

    Andrey_Karpov, 25 Октября 2011

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

    +70

    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
    for (AllResponseCache actionResponse : allResponses) {
                    if (null != actionResponse.getResponseStatus() && actionResponse.getResponseStatus().length() > 0) {
                        for (ResponseSubjectCache subj : actionResponse.getSubjects()) {
                            // find needed element
                            if (subj.getClaims() != null) {
                                for (ClaimCache claimCache : subj.getClaims()) {
                                    Seller seller = getSellerByPersonMatched(pool, claimCache);
                                    if (seller != null) {
                                        if (mapToSyncronize.get(seller) == null) {
                                            mapToSyncronize.put((SellerrEntity) seller, new LinkedList<ReportResponseCache>());
                                        }
                                        mapToSyncronize.get(seller).add(actionResponse);
                                    }
                                }
                            }
                        }
                    }
                }

    Индусы и "for-if"-ы.

    Я уж думал будет хронология как в России с "президентами" - "лысый, волосатый, лысый, волосатый" и так далее.
    А тут "for, if, for, if" но в конце всё-таки 2 иф-а!

    Dimedrol, 25 Октября 2011

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

    +160

    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
    $bError=true;
    do { 
    	$logistType = $_REQUEST['logistType'];
    	if (!preg_match("|^\d+$|", $logistType)) { break; }
    	if ($_SESSION['cartaddon']['***'] and $logistType>=1 and $logistType<=5) {
    	} elseif (!$_SESSION['cartaddon']['***'] and $logistType>=3 and $logistType<=5) {
    	} else {
    		break;
    	}
    	$_SESSION['cartaddon']['logistType'] = $logistType;
    	$bError = false;
    	$text = $_REQUEST['text'];
    	$text = trim(strip_tags($text));
    	$_SESSION['cartaddon']['pozhelania'] = $text;
    } while (0);

    Проверка если ли ошибки при оформлении заказа
    На месте звездочек - палевное название, так что зацензурил

    ПыСы: код не мой. И спасибо богам за это

    kindofbear, 25 Октября 2011

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

    +128

    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
    public class BusinessUnitDetail
    {
        public string Description { get; set; }
    }
    
    ...
    
    [TestMethod]
    public void DescriptionTest()
    {
        BusinessUnitDetail target = new BusinessUnitDetail(); 
        string expected = "test test test\n test"; 
        string actual;
        target.Description = expected;
        actual = target.Description;
        Assert.AreEqual(expected, actual);
    }

    беспощадная проверка всего и вся

    Eugene, 25 Октября 2011

    Комментарии (26)
  9. Java / Говнокод #8288

    +83

    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
    public static long getDifference(Date date1, Date date2, int unit) {
    	if (date1 == null || date2 == null) {
    		throw new IllegalArgumentException("Date cannot be null!");
    	}
    
    	if (date1.after(date2)) {
    		Date swap = date1;
    		date1 = date2;
    		date2 = swap;
    	}
    		
    	long result = 0;
    	
    	long diff = date2.getTime() - date1.getTime() + (60 * 60 * 1000L);
    		
    	switch (unit) {
    	case Calendar.YEAR:
    		result = diff / (60 * 60 * 24 * 365 * 1000L);
    		break;
    	case Calendar.MONTH:
    		result = diff / (60 * 60 * 24 * 30 * 1000L);
    		break;
    	case Calendar.DAY_OF_YEAR:
    		result = diff / (60 * 60 * 24 * 1000L);
    		break;
    	default:
    		throw new UnsupportedOperationException("Impossible to get time difference in coerced unit.");
    	}
    		
    	return result;
    }

    Опять даты, опять.... Java?
    Удивительно, но этот код использовался в вычислениях, связанных с начислением выплат. Разумеется, считалось всё неправильно, в связи с чем было обнаружено ЭТО.

    roman-kashitsyn, 25 Октября 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    vec->elements = realloc(vec->elements, sizeof(struct _vector_element)*newcapacity);
                if(vec->elements == NULL) {
                    // Lol. All your data is lost.
                    vc_set_error("Unable to allocate space for elements.");
                    return 1;
                }

    Автор не догадался сохранить старый указатель.

    danilissimus, 24 Октября 2011

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