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

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

    +159

    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
    public function asSize($value, $decimals = null, $options = [], $textOptions = [])
        {
            if ($value === null) {
                return $this->nullDisplay;
            }
            list($params, $position) = $this->formatSizeNumber($value, $decimals, $options, $textOptions);
            if ($this->sizeFormatBase == 1024) {
                switch ($position) {
                    case 0:  return Yii::t('yii', '{nFormatted} {n, plural, =1{byte} other{bytes}}', $params, $this->locale);
                    case 1:  return Yii::t('yii', '{nFormatted} {n, plural, =1{kibibyte} other{kibibytes}}', $params, $this->locale);
                    case 2:  return Yii::t('yii', '{nFormatted} {n, plural, =1{mebibyte} other{mebibytes}}', $params, $this->locale);
                    case 3:  return Yii::t('yii', '{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}', $params, $this->locale);
                    case 4:  return Yii::t('yii', '{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}', $params, $this->locale);
                    default: return Yii::t('yii', '{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}', $params, $this->locale);
                }
            } else {
                switch ($position) {
                    case 0:  return Yii::t('yii', '{nFormatted} {n, plural, =1{byte} other{bytes}}', $params, $this->locale);
                    case 1:  return Yii::t('yii', '{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}', $params, $this->locale);
                    case 2:  return Yii::t('yii', '{nFormatted} {n, plural, =1{megabyte} other{megabytes}}', $params, $this->locale);
                    case 3:  return Yii::t('yii', '{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}', $params, $this->locale);
                    case 4:  return Yii::t('yii', '{nFormatted} {n, plural, =1{terabyte} other{terabytes}}', $params, $this->locale);
                    default: return Yii::t('yii', '{nFormatted} {n, plural, =1{petabyte} other{petabytes}}', $params, $this->locale);
                }
            }
        }

    Yii продолжает свой крестовый поход против логики. Вам нужно немного другое форматирование, получить именно килобайты вместо кибибайтов? Выставьте какую-то ссаную внутреннюю переменную в значение, отличное от 1024. Да, двойка подойдет, не ссы, ставь.

    Fike, 30 Ноября 2014

    Комментарии (1)
  3. Pascal / Говнокод #17219

    +80

    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
    procedure TInventory.removeItem(userid: integer; invid: integer;amount: integer = 1);
    var
      MyRes: TInvItemArray;
      CurrItem: TInvItem;
      I,len: integer;
    begin
      if (amount <= 0) then
        exit;
      if (amount = 1) then
        begin
         db.removeItemFromUserInventory(GetItems(GetIndexByInvId(invid)),userid);
         FInventoryList.Remove(GetIndexByInvId(invid));
        end else
        begin
          if (amount >= finventorylist.Size) then
            exit;
          MyRes:=GetResources(invid);
          len:=length(myres);
          if (len = 0) then
            exit;
          if (amount > len) then
            exit;
          for i:=0 to len - 1 do
           begin
             curritem:=MyRes[i];
             db.removeItemFromUserInventory(GetItems(GetIndexByInvId(curritem.InvId)),userid);
             FInventoryList.Remove(GetIndexByInvId(curritem.invid));
           end;
         Setlength(myres,0);
        end;
    
    end;
    
    function TInventory.GetResources(invid: integer): TInvItemArray;
    function ToResult(var Return: TInvItemArray; const Item: TInvItem): Integer;
    begin
      Result := Length(Return);
      SetLength(Return, Result + 1);
      Return[Result] := Item;
    end;
    var
      item,sameitem: TInvItem;
      Resource: TItem;
      i: integer;
    begin
      SetLength(result,0);
      item:=GetItem(invid);
      if (item = nil) then
        exit;
      if (item.item <> nil) then
        begin
         // if (item.itemю = 30) then
         //   begin
              for i:=0 to FInventoryList.Size - 1 do
               begin
                 sameitem:=TInvItem(FInventoryList.Items[i]);
                  if (sameitem = nil) then
                    continue;
                 resource:=sameitem.item;
                  if (resource = nil) then
                    continue;
                  if (item.item.itemid = resource.itemid) then
                    ToResult(result,sameitem);
               end;
           // end;
        end;
    end;

    По сути - удалить объект из списка. OMG!

    Cynicrus, 29 Ноября 2014

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

    +154

    1. 1
    var coutryOption = commonSettings.parent().parent().parent().find("tr:contains('Country')");

    очень поиск...

    fess, 29 Ноября 2014

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

    +56

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    std::uint8_t octets[4];
    for(int i = 0; i < 4; ++i) {
        if(i != 0 && inp.get() != '.')
            { assert(false && "unexpected symbol"); }
        inp >> octets[i];
    }

    Два вида говна: в коде и в языке.

    Soul_re@ver, 28 Ноября 2014

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

    +133

    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
    if (*wpPat == L'\\')
        {
          wpCharStart=wpPat;
          if (++wpPat >= wpMaxPat) goto Error;
    
          if (*wpPat == L'x')
          {
            if (++wpPat >= wpMaxPat) goto Error;
    
            if (*wpPat == L'{')
            {
              wpStrTmp=++wpPat;
              for (;;)
              {
                if (wpPat >= wpMaxPat) goto Error;
                if (*wpPat++ == L'}') break;
              }
              if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
              {
                nPatChar=(int)hex2decW(wpStrTmp, (wpPat - 1) - wpStrTmp);
                if (nPatChar == -1)
                {
                  wpPat=wpStrTmp;
                  goto Error;
                }
                if (nPatChar <= MAXWORD)
                  lpREGroupItem->nGroupLen+=1;
                else
                  lpREGroupItem->nGroupLen+=2;
              }
            }
            else
            {
              if (wpPat + 2 > wpMaxPat)
                goto Error;
              wpPat+=2;
              if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
                ++lpREGroupItem->nGroupLen;
            }
          }
          else if (*wpPat == L'u')
          {
            if (wpPat + 5 > wpMaxPat)
              goto Error;
            wpPat+=5;
            if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
              ++lpREGroupItem->nGroupLen;
          }

    Регулярные велосипеды.
    Akelpad.

    gost, 25 Ноября 2014

    Комментарии (1)
  7. Си / Говнокод #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)
  8. Pascal / Говнокод #17165

    +88

    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
    function TCalc.getRewardItems(items : AnsiString; countItems : integer; userId : Integer; from:integer) : ISuperObject;
    var tmpFirstOdds : integer;
        strLines, extrLines : TStringList;
        strItems, strOdds, strOdds2: TIntegerList;
        i, j, tmpCountItems : integer;
        tmpOddsItems, sum : Integer;
        str: ansistring;
    begin
      Result := nil;
    
      // parse items line [id1,odd1],[id2,odd2],[id3,odd3]
      strLines := TStringList.Create;
      extrLines := TStringList.Create;
      strItems := TIntegerList.Create;
      strOdds := TIntegerList.Create;
      ExtractStrings(['[', ']'],[','], PChar(items), strLines);
      for i := 0 to strLines.Count - 1 do
      begin
        ExtractStrings([','],[' '], PChar(strLines[i]), extrLines);
        strItems.Add(StrToInt(extrLines[0]));
        strOdds.Add(StrToInt(extrLines[1]));
        extrLines.Clear;
      end;
    
      // calculate odds [a,b,c,d] as [a,a+b,a+b+c,a+b+c+d]
      sum := 0;
      strOdds2 := TIntegerList.Create;
      for i := 0 to strOdds.Count-1 do
      begin
        sum := sum + strOdds.Items[i];
        strOdds2.Add(sum);
      end;
    
      // select items
      str := '';
      for i := 0 to countItems - 1 do
      begin
        tmpFirstOdds := Random(101); // 0-100
        for j := 0 to strOdds2.Count-1 do
        begin
          if tmpFirstOdds < strOdds2.Items[j] then
          begin
            str := str + IntToStr(strItems[j]) + ',';
            break;
          end;
        end;
      end;
      str := '['+Copy(str,1,Length(str)-1)+']';
      // from monster
      if from=0 then Result := so('{"part":"battle","func":"itemsdropped","data":'+str+'}');
      // from chest
      if from=1 then Result := so('{"part":"battle","func":"itemsdroppedchest","data":'+str+'}');
      strLines.Free;
      extrLines.Free;
      strItems.Free;
      strOdds.Free;
      strOdds2.Free;
    end;

    У меня чуть глаза не вытекли от такого решения. Код по идее сообщает клиенту, что выпало из монстра после победы над ним.

    Cynicrus, 24 Ноября 2014

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

    +135

    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
    public void ValidateValue( ref object value ) {
                bool b;
                if ( value == null ) return;
                var typeName = BaseType.Name;
                var valueType = value.GetType();
                if ( valueType.Name == "String" ) {
                    if ( BaseType == valueType ) return;
                    if ( BaseType == Constants.Types.Boolean ) {
                        if ( string.Compare( "yes", (string) value, StringComparison.OrdinalIgnoreCase ) == 0 ) value = true;
                        else if ( string.Compare( "no", (string) value, StringComparison.OrdinalIgnoreCase ) == 0 ) value = false;
    #if !CF
                        else if ( Boolean.TryParse( value.ToString(), out b ) ) value = b;
    #else
              else if (TryParseUtility.TryParse(value.ToString(), out b)) value = b;
    #endif
                        else throw new ArgumentException( String.Format( Resources.ValueNotCorrectType, value ) );
                        return;
                    }
                }
    
    #if !CF
                if ( typeName == "Boolean"
                     && Boolean.TryParse( value.ToString(), out b ) ) {
                    value = b;
                    return;
                }
    
                UInt64 uintVal;
                if ( typeName.StartsWith( "UInt64" )
                     && UInt64.TryParse( value.ToString(), out uintVal ) ) {
                    value = uintVal;
                    return;
                }
    
                UInt32 uintVal32;
                if ( typeName.StartsWith( "UInt32" )
                     && UInt32.TryParse( value.ToString(), out uintVal32 ) ) {
                    value = uintVal32;
                    return;
                }
    
                long intVal;
                if ( typeName.StartsWith( "long" )
                     && long.TryParse( value.ToString(), out intVal ) ) {
                    value = intVal;
                    return;
                }
    
                int intVal32;
                if ( typeName.StartsWith( "Int32" )
                     && Int32.TryParse( value.ToString(), out intVal32 ) ) {
                    value = intVal32;
                    return;
                }
    #else
          if (typeName == "Boolean" && TryParseUtility.TryParse(value.ToString(), out b)) { value = b; return; }
    
          UInt64 uintVal;
          if (typeName.StartsWith("UInt64") && TryParseUtility.TryParse(value.ToString(), out uintVal)) { value = uintVal; return; }
    
          UInt32 uintVal32;
          if (typeName.StartsWith("UInt32") && TryParseUtility.TryParse(value.ToString(), out uintVal32)) { value = uintVal32; return; }
    
          long intVal;
          if (typeName.StartsWith("long") && TryParseUtility.TryParse(value.ToString(), out intVal)) { value = intVal; return; }
    
          Int32 intVal32;
          if (typeName.StartsWith("Int32") && TryParseUtility.TryParse(value.ToString(), out intVal32)) { value = intVal32; return; }
    #endif
    
                object objValue;
    #if RT
          Type baseType = BaseType.GetTypeInfo().BaseType;
    #else
                var baseType = BaseType.BaseType;
    #endif
                if ( baseType != null
                     && baseType.Name == "Enum"
                     && ParseEnum( value.ToString(), out objValue ) ) {
                    value = objValue;
                    return;
                }
    
                throw new ArgumentException( String.Format( Resources.ValueNotCorrectType, value ) );
            }

    MySql.Data 6.9.5, MySqlConnectionStringBuilder.cs

    kasthack, 24 Ноября 2014

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

    +51

    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
    std::list<COptions *> COptions::m_InstanceList;
    ..........
    COptions::COptions()
    {
    	for (int i = 0; i < OPTIONS_NUM; ++i)
    		m_OptionsCache[i].bCached = FALSE;
    	m_pOptionsHelperWindow = new COptionsHelperWindow(this);
    	simple_lock lock(m_mutex);
    #ifdef _DEBUG
    	for (std::list<COptions *>::iterator iter=m_InstanceList.begin(); iter != m_InstanceList.end(); ++iter)
    		ASSERT(*iter != this);
    #endif _DEBUG
    	m_InstanceList.push_back(this);
    	m_SpeedLimits[0] = m_sSpeedLimits[0];
    	m_SpeedLimits[1] = m_sSpeedLimits[1];
    }
    
    COptions::~COptions()
    {
    	{
    		simple_lock lock(m_mutex);
    		std::list<COptions *>::iterator iter;
    		for (iter=m_InstanceList.begin(); iter != m_InstanceList.end(); ++iter) {
    			if (*iter == this)
    				break;
    		}
    
    		ASSERT(iter != m_InstanceList.end());
    		if (iter != m_InstanceList.end())
    			m_InstanceList.erase(iter);
    	}
    
    	if (m_pOptionsHelperWindow)
    		delete m_pOptionsHelperWindow;
    	m_pOptionsHelperWindow=0;
    }
    .......

    В отладке включается тяжелый героиновый бред разработчиков FileZilla

    fsmoke, 24 Ноября 2014

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

    +49

    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
    void ZModulesDlg::OnDestroy(HWND hwnd)
    {
    	LVITEM lvi = { LVIF_PARAM };
    
    	if (lvi.iItem = ListView_GetItemCount(hwnd))
    	{
    		do 
    		{
    			lvi.iItem--;
    			if (ListView_GetItem(hwnd, &lvi))
    			{
    				((ZDll*)lvi.lParam)->Release();
    			}
    		} while (lvi.iItem);
    	}
    }

    zhukas, 17 Ноября 2014

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