1. Си / Говнокод #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)
  2. Си / Говнокод #17178

    +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
    if (wParam == MI_CMDLINEBEGIN)
              return xstrcpyW((void *)lParam, wpCmdLineBegin);
            if (wParam == MI_CMDLINEEND)
              return xstrcpyW((void *)lParam, wpCmdLineEnd);
            if (wParam == MI_SHOWMODIFY)
              return moCur.dwShowModify;
            if (wParam == MI_STATUSPOSTYPE)
              return moCur.dwStatusPosType;
            if (wParam == MI_STATUSUSERFORMAT)
              return xstrcpynW((void *)lParam, moCur.wszStatusUserFormat, MAX_PATH);
            if (wParam == MI_WORDBREAKCUSTOM)
              return moCur.dwWordBreakCustom;
            if (wParam == MI_PAINTOPTIONS)
              return moCur.dwPaintOptions;
            if (wParam == MI_EDITSTYLE)
              return moCur.dwEditStyle;
            if (wParam == MI_RICHEDITCLASS)
              return moCur.bRichEditClass;
            if (wParam == MI_AKELADMINRESIDENT)
              return moCur.bAkelAdminResident;
            if (wParam == MI_DATELOGFORMAT)
              return xstrcpynW((void *)lParam, moCur.wszDateLogFormat, 128);
            if (wParam == MI_DATEINSERTFORMAT)
              return xstrcpynW((void *)lParam, moCur.wszDateInsertFormat, 128);
            if (wParam == MI_AKELUPDATEROPTIONS)
              return xstrcpynW((void *)lParam, moCur.wszAkelUpdaterOptions, MAX_PATH);
            if (wParam == MI_URLCOMMAND)
              return xstrcpynW((void *)lParam, moCur.wszUrlCommand, MAX_PATH);
            if (wParam == MI_TABNAMEFIND)
              return xstrcpynW((void *)lParam, moCur.wszTabNameFind, MAX_PATH);
            if (wParam == MI_TABNAMEREP)
              return xstrcpynW((void *)lParam, moCur.wszTabNameRep, MAX_PATH);
            if (wParam == MI_ONTOP)
              return moCur.bOnTop;
            if (wParam == MI_STATUSBAR)
              return moCur.bStatusBar;
            if (wParam == MI_KEEPSPACE)
              return moCur.bKeepSpace;
            if (wParam == MI_WATCHFILE)
              return moCur.bWatchFile;
            if (wParam == MI_SAVETIME)
              return moCur.bSaveTime;
            if (wParam == MI_SINGLEOPENFILE)
              return moCur.bSingleOpenFile;
            if (wParam == MI_SINGLEOPENPROGRAM)
              return moCur.dwSingleOpenProgram;
            if (wParam == MI_TABOPTIONSMDI)
              return moCur.dwTabOptionsMDI;
            if (wParam == MI_EXECUTECOMMAND)

    И такого больше сотни строк.
    Akelpad.

    gost, 25 Ноября 2014

    Комментарии (14)
  3. Си / Говнокод #17177

    +132

    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
    LRESULT CALLBACK MainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
      if (uMsg == WM_CREATE)
      {
        int *lpSBParts;
        int iBorders[3];
        CLIENTCREATESTRUCT ccs;
        DWORD dwClassStyle;
        RECT rcRect;
        HMENU hMenu;
    
        hMainWnd=hWnd;
        hPopupEdit=GetSubMenu(hPopupMenu, MENU_POPUP_EDIT);
        hPopupView=GetSubMenu(hPopupMenu, MENU_POPUP_VIEW);
        hPopupCodepage=GetSubMenu(hPopupMenu, MENU_POPUP_CODEPAGE);
        hPopupOpenCodepage=GetSubMenu(hPopupCodepage, MENU_POPUP_CODEPAGE_OPEN);
        hPopupSaveCodepage=GetSubMenu(hPopupCodepage, MENU_POPUP_CODEPAGE_SAVE);
        hPopupHeadline=GetSubMenu(hPopupMenu, MENU_POPUP_HEADLINE);
    
        hMenu=GetSubMenu(hMainMenu, MENU_FILE_POSITION);
        hMenuRecentFiles=GetSubMenu(hMenu, MENU_FILE_RECENTFILES_4X);
        hMenu=GetSubMenu(hMainMenu, MENU_VIEW_POSITION);
        hMenuLanguage=GetSubMenu(hMenu, MENU_VIEW_LANGUAGE_4X);

    Плотная простынка, спать можно.
    Akelpad.

    gost, 25 Ноября 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int size;
    
    size = EXPR;
    
    if (size > INT_MAX || size <= 0) {
        return NULL;
    }
    
    // ...

    Ндя. Семь лет уже. Теперь всё понятно...

    bot, 23 Ноября 2014

    Комментарии (52)
  7. Си / Говнокод #17150

    +139

    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
    SGELISTENTRY *sgeListAdd(SGELIST *l, const char *id, void *data) {
       SGELISTENTRY *ret;
    
       sgeNew(ret, SGELISTENTRY);
       l->numberOfEntries++;
       if (l!=NULL) {
          ret->prev=l->last;
       } else {
          ret->prev=NULL;
       }
       if (l!=NULL && l->last!=NULL) {
          l->last->next=ret;
       }
       ret->next=NULL;
       ret->id=strdup(id);
       ret->data=data;
    
       if (l==NULL) return ret;
    
       if (l->first==NULL) l->first=ret;
       l->last=ret;
    
       return ret;
    }

    Эх, проверяй, не проверяй, один хрен все грохнется при l==NULL

    Pythoner, 21 Ноября 2014

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

    +136

    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
    len += sprintf(event_xml_msg, XML_TAG_START, XML_KOKOKO_HTTP_PROTOCOL);
    
    	// Set <monitor-event>
    	len += sprintf(strend_ptr(event_xml_msg), XML_TAG_START, XML_MONITOR_EVENT_NODE_TREE);
    
    	// Set <date>
    	len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_DATE, dt.date_b);
    
    	// Set <time>
    	len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_TIME, dt.time_b);
    
    	// Set <product> Ex. "VersAtive"
    	len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_PRODUCT, product_type);
    
    	// Set <entity code>
    	// Supposed to work for all union types
    	len += xml_int_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_CODE, event_code);
    
    	// Set <severity>
    	//	len += xml_int_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_SEVERITY, severity);
    	memset(severity_str, 0, sizeof(severity_str));
    	get_severity_string(severity, severity_str);
    	len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_SEVERITY, severity_str);
    
    	// Set event entity name
    	len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_ENTITY_TYPE, entity_name);
    
    	// Set event description
    	if((len + strlen(description)) > (payload_size - footer_size))
    	{
    		// TODO HANDLE
    		printf("Message description overflows buffer size.\n");
    		return false;
    	}
    	len += xml_cdata_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_DESCRIPTION, description);
    
    	// Set params
    	add_xml_entity_params(event_xml_msg, entity_params);
    
    	// Close <monitor-event>
    	sprintf(strend_ptr(event_xml_msg), XML_TAG_END, XML_MONITOR_EVENT_NODE_TREE);
    
    	// Close <HTTPProtocol>
    	len += sprintf(strend_ptr(event_xml_msg), XML_TAG_END, XML_KOKOKO_HTTP_PROTOCOL);

    В проекте широко используется libmxml, а вот блять использовать его по назначению велосипедики не могут.

    codemonkey, 20 Ноября 2014

    Комментарии (56)
  9. Си / Говнокод #17096

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static enum rc (*request_functions[])(void) = {
        ko,
        koko,
        kokoko,
        illegal_request
    };
    static inline enum rc illegal_request(void) { return ILLEGAL_REQUEST; }
    
    reply.rc = request_functions[cmd.opcode < NKEYS(request_functions) ? cmd.opcode : ILLEGAL_REQUEST]();

    Вызываем функцию по опкоду с абортом в случае index_out_of_bounds.

    codemonkey, 12 Ноября 2014

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

    +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
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    main(){    
        
        FILE *filein, *fileout;
        
        char fname1[15], fname2[15];
        int n, m;
        int i, j;
        
        printf("Enter name of input file: "); scanf("%s", &fname1);
        printf("Enter name of output file: "); scanf("%s", &fname2);
        
        filein=fopen(fname1, "r");
        fileout=fopen(fname2, "w");
        if(filein==NULL){
          fprintf(stderr, "\nError: can't open file \"%s\"\n\n", fname1);
          fclose(filein);
          fclose(fileout);
          getch();
          }
        else{
             fscanf(filein, "%d%d", &n, &m);
             char ch[m][n];
             int array[m][n];
             int V[m][n];
             
             for(i=0;i<m;i++){
                for(j=0;j<n;j++){
                   V[i][j]=0;
                   }
                }
             
             for(i=0;i<m;i++){
                for(j=0;j<n;j++){
                   fscanf(filein, "%s", &ch[i][j]);
                   if(ch[i][j]=='+') array[i][j]=1;
                   else if(ch[i][j]=='-') array[i][j]=0;
                   }
                }
             
             int sum;
             for(i=0;i<m;i++){
                sum=0;
                for(j=0;j<n;j++){
                   sum+=array[i][j];
                   }
                   if(sum==1){
                             for(j=0;j<n;j++){
                                V[i][j]=array[i][j];
                                }
                             }
                   else continue;
                }
                
             int mm=0, c;
             for(i=0;i<m;i++){
                for(j=0;j<n;j++){
                   mm+=V[i][j];
                   }
                }
             c = m-mm;
             
             int VoteArray[n];
             
             for(j=0;j<n;j++){
                sum=0;
                for(i=0;i<m;i++){
                   sum+=V[i][j];
                   VoteArray[j]=sum;
                   }
                }
             
             float percent[n];
             float per;
             per = 100/(float)c;
             for(i=0;i<n;i++){
                
                if((percent[i]=per*VoteArray[i])>=7.0) fprintf(fileout, "%d ", i+1);
                }
                
             }
        
        fclose(fileout);
        fclose(filein);
        puts("\nMission comleted\nPress any key...\n");
        getch();
    }

    Фу, блять

    Sushev, 09 Ноября 2014

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