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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for (int i = 0; i <= 10000; i++)
    {
    if (a[i]=='a')
    a[i] == "000";
    continue;
    }

    Цикл, который в строке a меняет все символы 'a' на три ноля. Говнолабка одногруппницы.

    b2soft, 25 Ноября 2014

    Комментарии (28)
  2. Java / Говнокод #17175

    +72

    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
    private String shutdown = "SHUTDOWN";
    
    ........
    
    // Read a set of characters from the socket
    int expected = 1024; // Cut off to avoid DoS attack
    
    <--Зачем это тут?-->
    while (expected < shutdown.length()) {
        if (random == null)
            random = new Random();
        expected += (random.nextInt() % 1024);
    }
    
    
    while (expected > 0) {
        int ch = -1;
        try {
            ch = stream.read();
        } catch (IOException e) {
            log.warn("StandardServer.await: read: ", e);
            ch = -1;
        }
        if (ch < 32)  // Control character or EOF terminates loop
            break;
        command.append((char) ch);
        expected--;
    }

    Не понимаю зачем тут while. Авторы Apache Tomcat расскажите...

    mrFoxs, 25 Ноября 2014

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

    +156

    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
    var move_container_after = function(toMove, toAfter) {
    	  $(toMove).insertAfter(toAfter);
    };
    
    var move_container_before = function(toMove, toBefore) {
    	  $(toMove).insertBefore(toBefore);
    };
    
    move_container_before(".toggle.basic1-tog", ".basic1 .store-order-item-group-action-list");
    move_container_after(".toggle.basic1rn-tog", ".basic1rn .store-order-item-description");
    
    move_container_before(".toggle.basic3-tog", ".basic3 .store-order-item-group-action-list");
    move_container_after(".toggle.basic3rn-tog", ".basic3rn .store-order-item-description");
    
    move_container_before(".toggle.bundle1-tog", ".bundle1 .store-order-item-group-action-list");
    move_container_after(".toggle.bundle1rn-tog", ".bundle1rn .store-order-item-group-action-list");
    
    move_container_before(".toggle.bundle12-tog", ".bundle12 .store-order-item-group-action-list");
    move_container_after(".toggle.bundle12rn-tog", ".bundle12rn .store-order-item-group-action-list");
    
    move_container_before(".toggle.bundle3-tog", ".bundle3 .store-order-item-group-action-list");
    move_container_after(".toggle.bundle3rn-tog", ".bundle3rn .store-order-item-group-action-list");
    
    move_container_before(".toggle.bundle6-tog", ".bundle6 .store-order-item-group-action-list");
    move_container_after(".toggle.bundle6rn-tog", ".bundle6rn .store-order-item-group-action-list");
    
    move_container_before(".toggle.desktop1-tog", ".desktop1 .store-order-item-group-action-list");
    move_container_after(".toggle.desktop1rn-tog", ".desktop1rn .store-order-item-description");
    
    move_container_before(".toggle.desktop12-tog", ".desktop12 .store-order-item-group-action-list");
    move_container_after(".toggle.desktop12rn-tog", ".desktop12rn .store-order-item-description");
    
    move_container_before(".toggle.desktop3-tog", ".desktop3 .store-order-item-group-action-list");
    move_container_after(".toggle.desktop3rn-tog", ".desktop3rn .store-order-item-description");
    
    move_container_before(".toggle.desktop6-tog", ".desktop6 .store-order-item-group-action-list");
    move_container_after(".toggle.desktop6rn-tog", ".desktop6rn .store-order-item-description");
    
    move_container_before(".toggle.desktopbus12-tog", ".desktopbus12 .store-order-item-group-action-list");
    move_container_after(".toggle.desktopbus12rn-tog", ".desktopbus12rn .store-order-item-description");   
    
    move_container_before(".toggle.desktopbus6-tog", ".desktopbus6 .store-order-item-group-action-list");
    move_container_after(".toggle.desktopbus6rn-tog", ".desktopbus6rn .store-order-item-description");
    
    move_container_before(".toggle.premium1-tog", ".premium1 .store-order-item-group-action-list");
    move_container_after(".toggle.premium1rn-tog", ".premium1rn .store-order-item-description");
    
    move_container_before(".toggle.premium12-tog", ".premium12 .store-order-item-group-action-list");
    move_container_after(".toggle.premium12rn-tog", ".premium12rn .store-order-item-description");
    
    move_container_before(".toggle.premium3-tog", ".premium3 .store-order-item-group-action-list");
    move_container_after(".toggle.premium3rn-tog", ".premium3rn .store-order-item-description");
    
    move_container_before(".toggle.premium6-tog", ".premium6 .store-order-item-group-action-list");
    move_container_after(".toggle.premium6rn-tog", ".premium6rn .store-order-item-description");
    
    move_container_before(".toggle.premiumbus12-tog", ".premiumbus12 .store-order-item-group-action-list");
    move_container_after(".toggle.premiumbus12rn-tog", ".premiumbus12rn .store-order-item-description");
    
    move_container_before(".toggle.premiumbus6-tog", ".premiumbus6 .store-order-item-group-action-list");
    move_container_after(".toggle.premiumbus6rn-tog", ".premiumbus6rn .store-order-item-description");

    "Перенос" формы, для каждого ID, в HTML есть соответствующее колово форм подобного типа

    <div class="toggle basic1-tog">Auto Renew: Off
    <form method="POST" action="https://sites.fastspring.com/store/api/order">
    <input type="hidden" name="operation" value="update"/>
    <input type="hidden" name="destination" value="checkout"/>
    <input type="hidden" name="product_1_path" value="/basicsubscription1monthrn"/>
    <input type="hidden" name="product_2_path" value="/basicsubscription1month"/>
    <input type="hidden" name="product_2_quantity" value="0"/>
    <input type="submit" value="Turn On"/>
    </form>
    </div>
    <div class="toggle basic1rn-tog">Auto Renew: On
    <form method="POST" action="https://sites.fastspring.com/store/api/order">
    <input type="hidden" name="operation" value="update"/>
    <input type="hidden" name="destination" value="checkout"/>
    <input type="hidden" name="product_1_path" value="/basicsubscription1month"/>
    <input type="hidden" name="product_2_path" value="/basicsubscription1monthrn"/>
    <input type="hidden" name="product_2_quantity" value="0"/>
    <input type="submit" value="Turn Off"/>
    </form>
    </div>

    IRIDON, 25 Ноября 2014

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

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    static inline uint64_t eight_bytes_to_uint64(uint8_t *buf) {
        return (uint64_t) four_bytes_to_uint32(buf) << 32 | four_bytes_to_uint32(buf + sizeof(uint32_t));
    }
    
    static inline uint32_t four_bytes_to_uint32(uint8_t *buf) {
        return (uint32_t) two_bytes_to_uint16(buf) << 16 | two_bytes_to_uint16(buf + sizeof(uint16_t));
    }
    
    static inline uint16_t two_bytes_to_uint16(uint8_t *buf) {
        return buf[0] << 8 | buf[1];
    }

    Чё-то вспомнились Schemeовые времена и ФП.

    Buffer overflow исключён на 146%.

    codemonkey, 25 Ноября 2014

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

    +134

    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
    //// AEM_* AkelEdit control messages
    
      if (uMsg >= WM_USER)
      {
        if (uMsg >= AEM_CANUNDO)
          goto CanUndo;
    
        //Text retrieval and modification
        if (uMsg == AEM_EXSETTEXTA)
        {
          AESETTEXTA *at=(AESETTEXTA *)lParam;
    
          return AE_SetTextAnsi(ae, at->nCodePage, at->pText, at->dwTextLen, at->nNewLine);
        }
        if (uMsg == AEM_EXSETTEXTW)
        {
          AESETTEXTW *at=(AESETTEXTW *)lParam;
    
          return AE_SetText(ae, at->pText, at->dwTextLen, at->nNewLine, FALSE);
        }
        if (uMsg == AEM_SETTEXTA)
        {
          return AE_SetTextAnsi(ae, CP_ACP, (char *)lParam, wParam, AELB_ASINPUT);
        }
        if (uMsg == AEM_SETTEXTW)
        {
          return AE_SetText(ae, (wchar_t *)lParam, wParam, AELB_ASINPUT, FALSE);
        }
        if (uMsg == AEM_APPENDTEXTA)
        {
          AEAPPENDTEXTA *at=(AEAPPENDTEXTA *)lParam;
    
          AE_AppendTextAnsi(ae, at->nCodePage, at->pText, at->dwTextLen, at->nNewLine);
          return 0;
        }
        if (uMsg == AEM_APPENDTEXTW)
        {
          AEAPPENDTEXTW *at=(AEAPPENDTEXTW *)lParam;
    
          AE_AppendText(ae, at->pText, at->dwTextLen, at->nNewLine);
          return 0;
        }
        if (uMsg == AEM_REPLACESELA)
        {
          AEREPLACESELA *rs=(AEREPLACESELA *)lParam;
    
          AE_ReplaceSelAnsi(ae, rs->nCodePage, rs->pText, rs->dwTextLen, rs->nNewLine, rs->dwFlags, rs->ciInsertStart, rs->ciInsertEnd);
          return 0;
        }
        if (uMsg == AEM_REPLACESELW)
        {
          AEREPLACESELW *rs=(AEREPLACESELW *)lParam;
    
          AE_ReplaceSel(ae, rs->pText, rs->dwTextLen, rs->nNewLine, rs->dwFlags, rs->ciInsertStart, rs->ciInsertEnd);
          return 0;
        }
        if (uMsg == AEM_GETTEXTRANGEA)
        {
          AETEXTRANGEA *tr=(AETEXTRANGEA *)lParam;
    
          return AE_GetTextRangeAnsi(ae, tr->nCodePage, tr->lpDefaultChar, tr->lpUsedDefChar, &tr->cr.ciMin, &tr->cr.ciMax, tr->pBuffer, tr->dwBufferMax, tr->nNewLine, tr->bColumnSel, tr->bFillSpaces);
        }

    И далее около сотни if'ов в таком духе.
    AkelPad

    gost, 25 Ноября 2014

    Комментарии (1)
  6. JavaScript / Говнокод #17171

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function in_array(value, array)
    {
        if (is_array(array)){
            for(var i = 0; i < array.length; i++)
            {
                if(array[i] == value) return true;
            }
            return false;
        }
    
    }

    от создателей http://govnokod.ru/17149

    heyzea1, 25 Ноября 2014

    Комментарии (11)
  7. Java / Говнокод #17170

    +74

    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
    if (convertView == null || convertView != null) {
                    if (Position2.get(position)) {
                        t.setVisibility(0);
                        b.setVisibility(4);
                        mlp.setMargins(15, 0, 60, 0);
                        y.setBackgroundColor(getResources().getColor(R.color.app_text_white));
                    } else {
                        mlp.setMargins(60, 0, 15, 0);
                        t.setVisibility(4);
                        b.setVisibility(0);
                        y.setBackgroundColor(getResources().getColor(R.color.app_text_white));                    
                    }
                } else {
                    view = convertView;
                }

    Индусы

    vinnizp, 25 Ноября 2014

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

    +57

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for (i = MAX_PATH; 5; i--){
        if (CurProfileF[i] == 't' && CurProfileF[i-3] == '.'){
            i = i-3;
            break;
        }
    }

    http://trac.miranda-ng.org/browser/trunk/protocols/Xfire/src/variables.cpp?rev=5315#L194

    roman-kashitsyn, 25 Ноября 2014

    Комментарии (9)
  9. SQL / Говнокод #17168

    −864

    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
    sResult:= '';
       select  code||' '||h.longname into sResult
            from tbl1 mo, tbl2 ob, g_cli c, tbl3 h
          where mo.m_dep_id = ob.obj_dep_id and mo.m_id = ob.obj_id
              and ob.dep_id = nDepId and ob.id = nId
              and  mo.cli_dep_id = c.dep_id and mo.cli_id = c.id
              and c.id = h.id and c.dep_id = h.dep_id and p_operday between h.FROMDATE and h.TODATE;
             return sResult; 
      exception
        when NO_DATA_FOUND then return null;
        when TOO_MANY_ROWS then          
              for rec in(   select  distinct code as cli_code, h.longname as cli_name 
            from tbl1 mo, tbl2 ob, g_cli c, tbl3 h
          where mo.m_dep_id = ob.obj_dep_id and mo.m_id = ob.obj_id
              and ob.dep_id = nDepId and ob.id = nId
              and  mo.cli_dep_id = c.dep_id and mo.cli_id = c.id
              and c.id = h.id and c.dep_id = h.dep_id and dT between h.FROMDATE and h.TODATE)
                loop
                  if nvl(length(sResult),0) = 0 then
                    sResult:= rec.cli_code||' '||rec.cli_name;
                  else
                    sResult:= sResult||', '||rec.cli_code||' '||rec.cli_name;
                  end if;
                end loop;
                return sResult;   
         when others then return null;

    ColvirBydlokod, 25 Ноября 2014

    Комментарии (3)
  10. PHP / Говнокод #17167

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    $arResult = Yii::app()->db->createCommand($sql)->queryRow();
    if ($arResult && isset($arResult) && is_array($arResult) && !empty($arResult['pk_report'])) {
        ...
    }

    проверить все, что скрыто

    cx44, 25 Ноября 2014

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