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

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

    +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
    #ifndef ORDER32_H
    #define ORDER32_H
    
    #include <limits.h>
    #include <stdint.h>
    
    #if CHAR_BIT != 8
    #error "unsupported char size"
    #endif
    
    enum
    {
        O32_LITTLE_ENDIAN = 0x03020100ul,
        O32_BIG_ENDIAN = 0x00010203ul,
        O32_PDP_ENDIAN = 0x01000302ul
    };
    
    static const union { unsigned char bytes[4]; uint32_t value; } o32_host_order =
        { { 0, 1, 2, 3 } };
    
    #define O32_HOST_ORDER (o32_host_order.value)
    
    #endif

    Говнокод из http://stackoverflow.com/questions/2100331/c-macro-definition-to-determine-big-endian-or-little-endian-machine
    Мало того, что писать в один тип из юниона и потом читать из другого это UB, так еще компилятор (в случае GCC) из

    int main(void)
    {return O32_HOST_ORDER == O32_LITTLE_ENDIAN;}

    нагенерирует код
    main:
    xor eax, eax
    cmp DWORD PTR o32_host_order[rip], 50462976
    sete al
    ret
    o32_host_order:
    .byte 0
    .byte 1
    .byte 2
    .byte 3

    т.е. всякий раз, когда надо узнать endianess, мы лезем в константную статическую переменную и сравниваем ее с константой

    j123123, 08 Апреля 2014

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

    +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
    procedure tproxythread.execute;
    var
      doc: IHtmlDocument2;
      temp,parsed:string;
      v:olevariant;
      i:integer;
    begin
      coinitialize(nil);
      try
        for i:=0 to links.count -1 do
        begin
          temp:=http.LoadContent(links[i]);
          Doc:=coHTMLDocument.Create as IHTMLDocument2;
          V:=VarArrayCreate([0,0], varVariant);
          V[0]:=temp;
          Doc.Write(PSafeArray(TVarData(v).VArray));
          reg.InputString:=doc.body.outerText;
          if reg.Exec then
          repeat
            parsed:= reg.Match [0];
            proxy.add(parsed);
          until not reg.ExecNext;
        end;
      finally
        couninitialize;
      end;
    end;

    Вы все еще парсите webbrowser-ом? Тогда мы идем к вам!..

    Stertor, 03 Апреля 2014

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

    +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
    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
    FRebuildSubdocPlcpcd(pdsr, ddsr, edcDrp)
    struct DSR *pdsr;
    int ddsr;
    int edcDrp;
    {
    /* we pull some tricks here because the normal editing situation doesn't cover
    	what we're trying to do:
    		1. We don't disturb the old chEop at the end of the subdoc until after
    			we have replaced the old pieces with the new one; then we delete it
    			surgically (we know it has either a different fn or noncontiguous
    			fc from the new stuff -- so just subtract ccpEop from cpMac and
    			remove the last pcd entry)
    		2. The plcfnd/plchdd needn't take part in the editing, since the CP
    			bounds will be the same after as they were before, and in fact
    			AdjustCp doesn't know how to handle editing the subdoc data -- so
    			we hide the plc from the editing
    */
    	int doc = pdsr->doc;
    	int docSubdoc;
    	int ipcd;
    	CP ccpSubdoc;
    
    	struct DOD *pdod;
    	struct PLC **hplcfnd;
    	struct PLC **hplcfld;
    	struct DRP *pdrp;
    	struct CA ca1, ca2;
    	struct PLC **hplcpcd, **hplcpcdSub;
    	CP *pccpSubdoc;
    	struct PCD pcd;
    
    	/*  momentarily break link to subdoc doc in dod so that ReplaceCps
    		doesn't get confused. */
    	pdrp = ((int *)PdodDoc(doc)) + edcDrp;
    	docSubdoc = pdrp->doc;
    	pccpSubdoc = ((int *)pdsr) + ddsr;
    	ccpSubdoc = *pccpSubdoc;
    	pdrp->doc = docNil;
    
    	if (docSubdoc != docNil && ccpSubdoc != cp0)
    		{
    		/* hide the subdoc plcfnd */
    		pdod = PdodDoc(docSubdoc);
    		hplcfnd = pdod->hplcfnd;
    		hplcfld = pdod->hplcfld;
    		pdod->hplcfnd = hNil;
    		pdod->hplcfld = hNil;
    
    		/* replace original piece table for subdoc with new --
    			note that we leave the chEop at end temporarily */
    		ccpSubdoc -= ccpEop;
    		if (!FReplaceCps(PcaSet(&ca1, docSubdoc, cp0, ccpSubdoc),
    				PcaSet(&ca2, doc, pdsr->ccpText, pdsr->ccpText + ccpSubdoc)))
    			return fFalse; 
    
    		/* now replace the PCD for the chEop left over from olden times;
    		   unfortunately, the editing routines can't do this for us */
    		hplcpcd = PdodDoc(doc)->hplcpcd;
    		if ((ipcd = IpcdSplit(hplcpcd, pdsr->ccpText + ccpSubdoc)) == iNil)
    			return fFalse;
    		GetPlc(hplcpcd, ipcd, &pcd);
    		hplcpcdSub = PdodDoc(docSubdoc)->hplcpcd;
    		PutPlc(hplcpcdSub, IMacPlc(hplcpcdSub) - 1, &pcd);
    		if ((ipcd = IpcdSplit(hplcpcdSub, ccpSubdoc+ccpEop)) == iNil)
    			return fFalse;
    		PutPlc(hplcpcdSub, ipcd-1, &pcd);
    
    		/* eliminate the footnote/header text from the main doc */
    		ca2.cpLim += ccpEop;
    		if (!FDelete(&ca2))
    			return fFalse;
    		pdod = PdodDoc(docSubdoc);
    
    		/* restore plcfnd */
    		pdod->hplcfnd = hplcfnd;
    		pdod->hplcfld = hplcfld;
    		pdod->fDirty = fFalse;
    
    		TruncateAllSels(docSubdoc, pdod->cpMac);
    		}
    
    	/* restore docFtn/docHdr */
    	pdrp = ((int *)PdodDoc(doc)) + edcDrp;
    	pdrp->doc = docSubdoc;
    
    	return fTrue;
    }

    Word for Windows 1.1a. 17 мегабайт отборного говнокода.

    http://habrahabr.ru/post/217081/

    gost, 26 Марта 2014

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

    +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
    try
                {
                    using (var context = new vbEntities())
                    {                   
                        
                        var DBF = new DBF();
                        var dt = DBF.GetAll(@"C:\Users\.........\Documents\BNKSEEK.DBF");
    
                        int i = 0;
                        progressBar1.Maximum = dt.Rows.Count;
    
                        foreach (DataRow dr in dt.Rows)
                        {
                            var row = new Bank();
                            row.BIK = dr["RKC"].ToString();
                            row.CityName = dr["NNP"].ToString();
                            row.Address = dr["ADR"].ToString();
                            row.Name = dr["NAMEP"].ToString();
                            row.KS = dr["KSNP"].ToString();
                            row.Phone = dr["TELEF"].ToString();
                            row.OKPO = dr["OKPO"].ToString();  
                            context.Bank.Add(row);
                            progressBar1.Value = i++;
                        }
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

    orozov, 18 Марта 2014

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

    +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
    if (other && other->client && other->s.number < MAX_CLIENTS)
    		{//player touched me
    			/*
    			char *text;
    			qboolean	keyTaken;
    			//give him my key
                            ...
    
    			*/
    			//rwwFIXMEFIXME: support for goodie/security keys?
    			/*
    			if ( keyTaken )
    			{//remove my key
    				NPC_SetSurfaceOnOff( self, "l_arm_key", 0x00000002 );
    				self->message = NULL;
    				//FIXME: temp pickup sound
    				G_Sound( player, G_SoundIndex( "sound/weapons/key_pkup.wav" ) );
    				//FIXME: need some event to pass to cgame for sound/graphic/message?
    			}
    			//FIXME: temp message
    			gi.SendServerCommand( NULL, text );
    			*/
    		}

    FIXMEFIXMEFIXME... Да ну нахуй, лучше все закомментим.

    gost, 15 Марта 2014

    Комментарии (38)
  7. Куча / Говнокод #15461

    +133

    1. 1
    access denied for the user "King1986" with password "weakCocc".

    Часть строки из лога. Логи пока общедоступны.

    laMer007, 13 Марта 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    //Смешались в кучу кони, люди...
    //знаю, что не комильфо писать запрос в контролере, но уже поссрать... ("поССрать", © 2014, Gary)
    $tempo = $this->db->query("SELECT `price_lists`.`id`, `companies`.`company_id`, `companies`.`name`  FROM `price_lists` LEFT JOIN `companies` ON `companies`.`company_id` = `price_lists`.`postovchik_id`")->result();
    $data['pricelistzgrrrrrrrrrr'] = array();
    if (is_array($tempo) && count($tempo)) {
        foreach ($tempo as $postovchik) {
            $data['pricelistzgrrrrrrrrrr'][$postovchik->id] = $postovchik->name;
        }
    }

    Gary, 27 Февраля 2014

    Комментарии (6)
  9. PHP / Говнокод #14757

    +133

    1. 1
    2. 2
    3. 3
    foreach ($_REQUEST['id'] as $id) {
    $db->execute('DELETE FROM `comments` WHERE `id` = ?', $id);
    }

    удаление нескольких комментариев по id

    dead_star, 21 Февраля 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    string dirUp = striBuildDir + striBinaryDir + "\\" + striTempDir + "\\";
     string dirRelease = strDirBin;
     int i = 1;
     while (ConfigurationSettings.AppSettings["SettingDir" + i] != null)
      {

    и еще строк 100500 такого же стиля

    taburetka, 12 Февраля 2014

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

    +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
    for (int idx = 0; idx < response.Length; ++idx)
    {
        try
        {
            if (getDetails(username, password, summaryList[idx].summaryId).productId[0].id != productId)
            {
            }
        }
        catch (NullReferenceException)
        {
        }
        catch (System.ArgumentException)
        {
            response[idx] = new DetailInfo();
        }
    }

    Если вы меня понимаете, .

    wissenstein, 11 Февраля 2014

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