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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    struct tm lpstTimeRecordRet;
    struct tm lpstTimeRecord;
    
    lpstTimeRecordRet = *localtime_r ( &potiUnixTime, &lpstTimeRecord);

    *фейс палм*

    Dummy00001, 02 Февраля 2012

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

    +131

    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
    #include <stdio.h>
    #include <math.h>
    void out_bin (unsigned short c){
    	for (int i = 11; i>=0; i--) {
    		if ((c & (unsigned short)(1<<i))/(1<<i)==1) printf("1");
    		else printf("0");
    	}
    	printf("\n");
    }
    int main (){
    	int a[8]={2,4,5,6,8,9,10,11};
    	int b[4]={0,1,3,7};
    	int d=0;
    	unsigned short int c=0,c1[4]={0,0,0,0};
    	unsigned char data=165,tdata=176;
    	for(int i=7;i>=0;i--)
    	{ 
    		if (tdata & 128){
    			c+=(unsigned short )(1<<a[i]);
    		}
    		tdata<<=1;
    	}
    	for (int i=0;i<8;i++){
    		unsigned short b = (unsigned short)((c & (unsigned short)(1<<a[i]))/(1<<a[i])) ;
    		if(a[i] & 1) c1[0]^=b;
    		else
    			if(a[i] & 2) c1[1]^=b ;
    			else
    				if(a[i] & 4) c1[2]^=b ;
    				else
    					if(a[i] & 8) c1[3]^=b ;
    	}
    	for (int i = 0; i < 4; i++) {
    		if (!c1[i]) {
    			c|=(unsigned short)(1<<((1<<i)-1));
    		}
    	}
    	printf("Data=      ");
    	out_bin(c);
    	c ^= 256 ;
    	if ((((c & 1024)/1024) ^ ((c & 256)/256) ^ ((c & 64)/64) ^ ((c & 16)/16) ^ ((c & 4)/4) ^ ((c & 1)/1) ) !=1 ){
    		d += 1;
    	}
    	if ((((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 4)/4) ^ ((c & 2)/2) )  !=1 ){
    		d +=2;
    	}  
    	if ((((c & 2048)/2048) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 16)/16) ^ ((c & 8)/8) ) !=1 ){
    		d +=4;
    	}
    	if ((((c & 2048)/2048) ^ ((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 256)/256) ^ ((c & 128)/128) )!=1 ){
    		d+=8;
    	}
    	printf("Spoiled=   ");
    	out_bin(c);
    	printf("%d",d);
    	if (d){
    			c ^=(1<<(d-1));
    	}
    	printf("Corrected= ");
    	out_bin(c);
    	return 0;
    }

    Код Хэмминга

    Abbath, 13 Января 2012

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

    +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
    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
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <time.h>
    char a[150],c[150];
    int main(int argc, char **argv) {	
    	FILE * tmp;
    	while(1) {
    		int b=0,b1=0;
    		bool A=0;
    		tmp=fopen(".tmp.txt","r");
    		fgets(c,150,tmp);
    		fclose(tmp);
    		system("rm .tmp.txt");
    		system("xwininfo -tree -root | grep -i '\\- deadbeef-0.5.1' > .tmp.txt");
    		tmp=fopen(".tmp.txt","r");
    		fgets(a,150,tmp);
    		fclose(tmp);
    		for(int i=16;i<149;i++) {
    
    			c[i-16]=c[i];
    			a[i-16]=a[i];
    			if(a[i-16]=='-')
    				b++;
    			if(c[i-16]=='-')
    				b1++;
    			if(b==2)
    				a[i-16]=0;
    			if(b1==2)
    				c[i-16]=0;
    		}
    		for(int j=0;j<(int)strlen(c);j++) {
    			if (a[j]!=c[j])	A=true;
    		}
    		if (A) {
    			char lamp[]="/usr/bin/purple-remote \"setstatus?status=available&message=";
    			strcat(lamp,a);
    			strcat(lamp,"\"");
    			system(lamp);
    		}
    		sleep(5);
    	}
    	return 0;
    }

    Реализация аналога pidgin-musictracker для deadbeef

    Abbath, 13 Января 2012

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

    +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
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    #include "stdio.h"
    #include "string.h"
    int main (int argc, char *argv[])
    {
    	FILE * f1= fopen("новый файл","r");
    	char a[3];
    	char * b= &a[0];
    	int i=0;
    	for (i = 0; i < 80; i ++)
    	{
    		char a1[400]="java -jar TextCode.jar ";
    		char a2[40]="/home/dan/Education/Subj/MFCIT/roz/";
    		fscanf(f1,"%s",b);
    		strcat(a1,a2);
    		strcat(a1,b);
    		strcat(a1,"/");
    		strcat(a1,b);
    		strcat(a1," ");
    		strcat(a1,a2);
    		strcat(a1,b);
    		strcat(a1,"/");
    		strcat(a1,b);
    		strcat(a1,".c ");
    		strcat(a1,a2);
    		strcat(a1,b);
    		strcat(a1,"/");
    		strcat(a1,b);
    		strcat(a1,".cod");
    		system(a1);
    	}
    	return 0;
    }

    Шифрует тексты при помощи проги на Java

    Abbath, 12 Января 2012

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

    +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
    static BOOL CALLBACK callbackEspecial(
      LPSTR aModuleName,
      DWORD aModuleBase,
      ULONG aModuleSize,
      PVOID aUserContext)
    {
        BOOL retval = TRUE;
        DWORD addr = *(DWORD*)aUserContext;
    
        /*
         * You'll want to control this if we are running on an
         *  architecture where the addresses go the other direction.
         * Not sure this is even a realistic consideration.
         */
        const BOOL addressIncreases = TRUE;
    
        /*
         * If it falls inside the known range, load the symbols.
         */
        if (addressIncreases
           ? (addr >= aModuleBase && addr <= (aModuleBase + aModuleSize))
           : (addr <= aModuleBase && addr >= (aModuleBase - aModuleSize))
            ) {
            retval = _SymLoadModule(GetCurrentProcess(), NULL, aModuleName, NULL, aModuleBase, aModuleSize);
        }
    
        return retval;
    }

    аццкая адресация
    http://mozilla-thunderbird.sourcearchive.com/documentation/1.5.0.10-0ubuntu3/nsStackFrameWin_8cpp-source.html

    63F45EF45RB65R6VR, 10 Января 2012

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

    +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
    try {
            // ....
     } except(EXCEPTION_EXECUTE_HANDLER) {
            Err = ERROR_INVALID_PARAMETER;
            //
            // Access the following variables here so that the compiler will respect our statement
            // ordering w.r.t. these values.  Otherwise, we can't be sure that the values are accurate
            // at the point where the exception occurred.
            //
            Buffer = Buffer;
            Array = Array;
            i = i;
        }

    втф?

    mazafaker666, 10 Января 2012

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

    +142

    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
    static inline gboolean is_alt(const gchar* string)
    {
    	return ((string[0] == '<') &&
    		(string[1] == 'a' || string[1] == 'A') &&
    		(string[2] == 'l' || string[2] == 'L') &&
    		(string[3] == 't' || string[3] == 'T') &&
    		(string[4] == '>'));
    }
    
    static inline gboolean is_ctl (const gchar* string)
    {
    	return ((string[0] == '<') &&
    		(string[1] == 'c' || string[1] == 'C') &&
    		(string[2] == 't' || string[2] == 'T') &&
    		(string[3] == 'l' || string[3] == 'L') &&
    		(string[4] == '>'));
    }
    
    static inline gboolean is_modx(const gchar* string)
    {
    	return ((string[0] == '<') &&
    		(string[1] == 'm' || string[1] == 'M') &&
    		(string[2] == 'o' || string[2] == 'O') &&
    		(string[3] == 'd' || string[3] == 'D') &&
    		(string[4] >= '1' && string[4] <= '5') &&
    		(string[5] == '>'));
    }
    
    static inline gboolean is_ctrl(const gchar* string)
    {
    	return ((string[0] == '<') &&
    		(string[1] == 'c' || string[1] == 'C') &&
    		(string[2] == 't' || string[2] == 'T') &&
    		(string[3] == 'r' || string[3] == 'R') &&
    		(string[4] == 'l' || string[4] == 'L') &&
    		(string[5] == '>'));
    }
    
    static inline gboolean is_shft (const gchar* string)
    {
    	return ((string[0] == '<') &&
    		(string[1] == 's' || string[1] == 'S') &&
    		(string[2] == 'h' || string[2] == 'H') &&
    		(string[3] == 'f' || string[3] == 'F') &&
    		(string[4] == 't' || string[4] == 'T') &&
    		(string[5] == '>'));
    }
    
    // ... (ещё 100500 подобных функций)
    // ... а тем временем где-то ниже:
    
    	  if (len >= 9 && is_release (accelerator))
    	    {
    	      accelerator += 9;
    	      len -= 9;
    	      mods |= EGG_VIRTUAL_RELEASE_MASK;
    	    }
    	  else if (len >= 9 && is_control (accelerator))
    	    {
    	      accelerator += 9;
    	      len -= 9;
    	      mods |= EGG_VIRTUAL_CONTROL_MASK;
    	    }
    	  else if (len >= 9 && is_primary (accelerator))
    	    {
    	      accelerator += 9;
    	      len -= 9;
    	      mods |= EGG_VIRTUAL_CONTROL_MASK;
    	    }
    	  else if (len >= 7 && is_shift (accelerator))
    	    {
    	      accelerator += 7;
    	      len -= 7;
    	      mods |= EGG_VIRTUAL_SHIFT_MASK;
    	    }
    	  else if (len >= 6 && is_shft (accelerator))
    	    {
    	      accelerator += 6;
    	      len -= 6;
    	      mods |= EGG_VIRTUAL_SHIFT_MASK;
    	    }
    	  else if (len >= 6 && is_ctrl (accelerator))
    	    {
    	      accelerator += 6;
    	      len -= 6;
    	      mods |= EGG_VIRTUAL_CONTROL_MASK;
    	    }
    
    // ... и так далее. код целиком сюда просто не влезет.

    шедевр. что сравнение строк, что цепочка if-else. все хороши.

    полной версией можно насладиться тут:
    https://github.com/mate-desktop/mate-control-center/blob/master/capplets/keybindings/eggaccelerators.c

    angry C nerd, 06 Января 2012

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

    +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
    #include<conio.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    void main() {
    clrscr();
    int i,j,k=0,n=6,l;
    float x[6],y[6],s[11],t[6],ur[6][7],s1;
    
    x[0]=0.1;   y[0]=0.25;
    x[1]=0.3;   y[1]=0.5;
    x[2]=0.4;   y[2]=0.65;
    x[3]=0.6;   y[3]=0.55;
    x[4]=0.7;   y[4]=0.42;
    x[5]=0.8;   y[5]=0.3;
    
    
    for(i=0;i<6;i++) {
    s[i]=0;
    for(j=0;j<6;j++)
    s[i]+=exp(i*log(x[j]));
    printf("%.2f\n",s[i]);
    
    }
    
    for(i=0;i<6;i++){
    t[i]=0;
    for(j=0;j<6;j++)
    t[i]+=pow(x[j],i)*y[j];}
    
    //----------------------------Gaus-----------------
    for(i=0;i<6;i++)
    for(j=0;j<7;j++)
    ur[i][j]=0;
    
    l=3;
    for(i=0;i<6;i++) {
    k=0;
    for(j=i;j<l;j++){
    
    
    ur[i][k]=s[j];
    k++;}
    
    ur[i][k]=t[i];
    l++;
    }
    n=3;
    ur[0][0]=s[0]; ur[0][1]=s[1]; ur[0][2]=s[2]; ur[0][3]=s[3]; ur[0][4]=s[4]; ur[0][5]=s[5]; ur[0][6]=t[0];
    ur[1][0]=s[1]; ur[1][1]=s[2]; ur[1][2]=s[3]; ur[1][3]=s[4]; ur[1][4]=s[5]; ur[1][5]=s[6]; ur[1][6]=t[1];
    ur[2][0]=s[2]; ur[2][1]=s[3]; ur[2][2]=s[4]; ur[2][3]=s[5]; ur[2][4]=s[6]; ur[2][5]=s[7]; ur[2][6]=t[2];
    ur[3][0]=s[3]; ur[3][1]=s[4]; ur[3][2]=s[5]; ur[3][3]=s[6]; ur[3][4]=s[7]; ur[3][5]=s[8]; ur[3][6]=t[3];
    ur[4][0]=s[4]; ur[4][1]=s[5]; ur[4][2]=s[6]; ur[4][3]=s[7]; ur[4][4]=s[8]; ur[4][5]=s[9]; ur[4][6]=t[4];
    ur[5][0]=s[5]; ur[5][1]=s[6]; ur[5][2]=s[7]; ur[5][3]=s[8]; ur[5][4]=s[9]; ur[5][5]=s[10]; ur[5][6]=t[5];
      
    ur[0][0]=6.0; ur[0][1]=2.90; ur[0][2]=1.75; ur[0][3]=1.16; ur[0][4]=0.81; ur[0][5]=0.59; ur[0][6]=2.67;
    ur[1][0]=2.90; ur[1][1]=1.75; ur[1][2]=1.16; ur[1][3]=0.81; ur[1][4]=0.59; ur[1][5]=0.43; ur[1][6]=1.30;
    ur[2][0]=1.75; ur[2][1]=1.16; ur[2][2]=0.81; ur[2][3]=0.59; ur[2][4]=0.43; ur[2][5]=0.32; ur[2][6]=0.75;
    ur[3][0]=1.16; ur[3][1]=0.81; ur[3][2]=0.59; ur[3][3]=0.43; ur[3][4]=0.32; ur[3][5]=0.24; ur[3][6]=0.47;
    ur[4][0]=0.81; ur[4][1]=0.59; ur[4][2]=0.43; ur[4][3]=0.32; ur[4][4]=0.24; ur[4][5]=0.18; ur[4][6]=0.32;
    ur[5][0]=0.59; ur[5][1]=0.43; ur[5][2]=0.32; ur[5][3]=0.24; ur[5][4]=0.18; ur[5][5]=0.14; ur[5][6]=0.22;
    ...

    Убило реализация степени ввиде exp, и мега инициализация)

    Bogdand, 19 Декабря 2011

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

    +104

    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
    // старый "медленый" код, проверяем размеры по именам файлов (последний параметр):
    
      if((checkFileLimits(_logTimeLimit,_logSizeLimit,_logStartTime,_traceFile1)>0) ||
         (checkFileLimits(_logTimeLimit,_logSizeLimit,_logStartTime,_traceFile2)>0) ||
         (checkFileLimits(_logTimeLimit,_logSizeLimit,_logStartTime,_traceFile3)>0) ||
         (checkFileLimits(_logTimeLimit,_logSizeLimit,_logStartTime,_traceFile) >0) )
    
    // новый "быстрый" код, проверяем размеры по файл хэндлам:
    
      FILE* fp1 = fopen(_traceFile1, "r");
      FILE* fp2 = fopen(_traceFile2, "r");
      FILE* fp3 = fopen(_traceFile3, "r");
      FILE* fp4 = fopen(_traceFile, "r");
      
      if((checkFileLimitsHandle(_logTimeLimit,_logSizeLimit,_logStartTime,fp1)>0) ||
         (checkFileLimitsHandle(_logTimeLimit,_logSizeLimit,_logStartTime,fp2)>0) ||
         (checkFileLimitsHandle(_logTimeLimit,_logSizeLimit,_logStartTime,fp3)>0) ||
         (checkFileLimitsHandle(_logTimeLimit,_logSizeLimit,_logStartTime,fp4) >0) )
             setTraceFile(NULL);
    
      fclose(fp1);
      fclose(fp2);
      fclose(fp3);
      fclose(fp4);

    наши бенчмаркеры чего-то там тестировали (на NFS!!!) и нашли что некоторые модули/библиотеки используют stat() вместо fstat()/ftell() для определения размера лог/трейс файлов (для ротации этих файлов). stat() берет как параметр не хэндл, а имя файла и поэтому дороже с точки зрения производительности. в особенности на NFS. ну начальник R&D и постановил: все stat()ы заменить на fstat()/ftell(). сказано - сделано. кусок сверху из модуля который пользуется внешней либой для логов и трейсов и у которого доступа к хэндлам нету. но герои не ищут легких путей: открываем файлы, получаем хэндлы, проверяем оптимальным образом размер файлов по хэндлам, закрываем файлы, гатова!

    Dummy00001, 14 Декабря 2011

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

    +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
    /*
     * HttpReceiveRequestEntityBody
     */
    static ULONG __cdecl
    HttpReceiveRequestEntityBody_called(BOOL carry_on,
                                        DWORD ret_addr,
                                        HANDLE ReqQueueHandle,
                                        HTTP_REQUEST_ID RequestId,
                                        ULONG Flags,
                                        PVOID pBuffer,
                                        ULONG BufferLength,
                                        PULONG pBytesReceived,
                                        LPOVERLAPPED pOverlapped)
    {
        if (GetCurrentThreadId() != cur_thread_id && ReqQueueHandle == cur_req_queue)
        {
            carry_on = FALSE;
            return ERROR_IO_PENDING; /* evil evil */
        }
    
        return 0;
    }

    нет что бы что то путнее в комментарии написать :)

    63F45EF45RB65R6VR, 12 Декабря 2011

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