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

    +1

    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
    /* 
    ================== 
    CL_ScreenshotGetName
    ================== 
    */  
    void CL_ScreenshotGetName( int lastnum, char *filename )
    {
    	int	a, b, c, d;
    
    	if( lastnum < 0 || lastnum > 9999 )
    	{
    		// bound
    		Q_sprintf( filename, "scrshots/%s/!error.bmp", clgame.mapname );
    		return;
    	}
    
    	a = lastnum / 1000;
    	lastnum -= a * 1000;
    	b = lastnum / 100;
    	lastnum -= b * 100;
    	c = lastnum / 10;
    	lastnum -= c * 10;
    	d = lastnum;
    
    	Q_sprintf( filename, "scrshots/%s_shot%i%i%i%i.bmp", clgame.mapname, a, b, c, d );
    }

    один вопрос: НАХУЯ???

    mittorn, 18 Июля 2017

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

    0

    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
    char*a??(??)=??<
    "??=include",
    "??=include",
    "??=define o stdout",
    "??=define b break;case",
    "??=define s(p)fputs(p,o);",
    "??=define c(p)fputc(p,o);",
    "void t(p,f)char*p;????/")b'??(':s(??/"???/??/?(??/")b'??)'",
    ":s(??/"???/??/?)??/")b'??/??/??/??/':f&&s(??/"???/??/?/??/")",
    "s(??/"???/??/?/??/")b'??/??/n':if(f)s(??/"???/??/?/n??/")",
    "else case'??/"':if(f)s(??/"???/??/?/??/??/??/"??/")",
    "else default:c(*p)??>??>??>main()??;??/",0);for(p=a",
    ";*p;p++)t(*p,0);exit(!ferror(o)&&",
    "!fclose(o)?EXIT_SUCCESS",
    ":EXIT_FAILURE);",
    "/*NOTREACHED*/",
    "??>",
    0??>;
    ??=include
    ??=include
    ??=define o stdout
    ??=define b break;case
    ??=define s(p)fputs(p,o);
    ??=define c(p)fputc(p,o);
    void t(p,f)char*p;??':s("???/?>")b'??(':s("???/?(")b'??)'
    :s("???/?)")b'??/??/':f&&s("???/?/")
    s("???/?/")b'??/n':if(f)s("???/?/n")
    else case'"':if(f)s("???/?/??/"")
    else default:c(*p)??>??>??>main()??;",0);for(p=a
    ;*p;p++)t(*p,0);exit(!ferror(o)&&
    !fclose(o)?EXIT_SUCCESS
    :EXIT_FAILURE);
    /*NOTREACHED*/
    ??>

    Очередной куайн. Херня на триграфах. Взято отсюда

    http://www.nyx.net/~gthompso/self_c.txt


    Там разумеется есть намного более ебанутые варианты

    j123123, 16 Июля 2017

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

    0

    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
    #include <stdio.h>
    char s[];
    int main ()
    {
        printf ("%s", s);
        for (char *s_p = s; *s_p; s_p++ )
        {
            printf ("%i,", *s_p);
        }
        printf ("};\n");
        return 0;
    }
    
    char s[] = R"(#include <stdio.h>
    char s[];
    int main ()
    {
        printf ("%s", s);
        for (char *s_p = s; *s_p; s_p++ )
        {
            printf ("%i,", *s_p);
        }
        printf ("};\n");
        return 0;
    }
    
    char s[] = {)";

    https://wandbox.org/permlink/uOQ7Uk6uFt4WVS2Y
    код на особом диалекте си (-std=gnu11) который генерирует код на более-менее обычном си (-std=c99) и этот сгенерированный код умеет будет генерировать сам себя
    Основано на сраной параше под названием raw string literals http://govnokod.ru/23178#comment388392 которая оказывается что поддерживается в особом диалекте си (-std=gnu11) https://stackoverflow.com/a/24850262

    j123123, 16 Июля 2017

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

    +2

    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
    #include <stdint.h>
    #include <stdio.h>
    
    char a[] = {35,105,110,99,108,117,100,101,32,60,115,116,100,105,110,116,46,104,62,10,35,105,110,99,108,117,100,101,32,60,115,116,100,105,111,46,104,62,10,10,99,104,97,114,32,97,91,93,32,61,32,123,0,125,59,10,10,105,110,116,32,109,97,105,110,40,118,111,105,100,41,10,123,10,32,32,105,110,116,32,98,59,10,32,32,98,32,61,32,112,114,105,110,116,102,40,34,37,115,34,44,32,97,41,59,10,32,32,102,111,114,32,40,99,104,97,114,32,42,105,32,61,32,97,59,32,105,32,60,32,97,32,43,32,115,105,122,101,111,102,40,97,41,59,32,105,43,43,41,10,32,32,123,10,32,32,32,32,112,114,105,110,116,102,40,34,37,105,44,34,44,32,42,105,41,59,10,32,32,125,10,32,32,112,114,105,110,116,102,40,34,37,115,34,44,32,97,43,98,43,49,41,59,10,32,32,114,101,116,117,114,110,32,48,59,10,125,10,};
    
    int main(void)
    {
      int b;
      b = printf("%s", a);
      for (char *i = a; i < a + sizeof(a); i++)
      {
        printf("%i,", *i);
      }
      printf("%s", a+b+1);
      return 0;
    }

    куайн на сишечке

    j123123, 12 Июля 2017

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

    +5

    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
    inline int ms_001(int x){ return    x                                                ;}    //  x * 1
    inline int ms_002(int x){ return    x<<1                                             ;}    //  x * 2  
    inline int ms_003(int x){ return    x<<2 - x                                         ;}    //  x * 3  
    ...
    inline int ms_799(int x){ return    x<<10 - x<<8 + x<<5 - x                          ;}    //  x * 799
    inline int ms_800(int x){ return    x<<10 - x<<8 + x<<5                              ;}    //  x * 800
    
    // массив указателей 
      int ( *mult_shift[800] ) (int) = {
                                            ms_001,              
                                            ms_002,
    ...
                                            ms_799,
                                            ms_800  };

    Очень быстрое целочисленное умножение

    fse, 12 Июля 2017

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

    −1

    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
    static bool
    do_convert(iconv_t cd, const char * src, int src_len,
               char ** dst, int *dst_len)
      {
      char * ret;
    
      char *inbuf;
      char *outbuf;
      int alloc_size;
      int output_pos;
      size_t inbytesleft;
      size_t outbytesleft;
    
      if(src_len < 0)
        src_len = strlen(src);
    #if 0
      fprintf(stderr, "Converting:\n");
      bgav_hexdump(src, src_len, 16);
    #endif
      alloc_size = src_len + BYTES_INCREMENT;
    
      inbytesleft  = src_len;
    
      /* We reserve space here to add a final '\0' */
      outbytesleft = alloc_size-1;
    
      ret    = malloc(alloc_size);
    
      inbuf  = (char *)src;
      outbuf = ret;
    
      while(1)
        {
    
        if(iconv(cd, (ICONV_CONST char **)&inbuf, &inbytesleft,
                 &outbuf, &outbytesleft) == (size_t)-1)
          {
          switch(errno)
            {
            case E2BIG:
              output_pos = (int)(outbuf - ret);
    
              alloc_size   += BYTES_INCREMENT;
              outbytesleft += BYTES_INCREMENT;
    
              ret = realloc(ret, alloc_size);
              if (ret == NULL)
                {
                cdio_warn("Can't realloc(%d).", alloc_size);
                return false;
                }
              outbuf = ret + output_pos;
              break;
            default:
              cdio_warn("Iconv failed: %s", strerror(errno));
              if (ret != NULL)
                free(ret);
              return false;
              break;
            }
          }
        if(!inbytesleft)
          break;
        }
      /* Zero terminate */
      *outbuf = '\0';
    
      /* Set return values */
      *dst = ret;
      if(dst_len)
        *dst_len = (int)(outbuf - ret);
    #if 0
      fprintf(stderr, "Conversion done, src:\n");
      bgav_hexdump(src, src_len, 16);
      fprintf(stderr, "dst:\n");
      bgav_hexdump((uint8_t*)(ret), (int)(outbuf - ret), 16);
    #endif
      return true;
    }

    https://github.com/pbatard/rufus/blob/edcfd43ed550b17f23f9534f4b3b5cdd7fffdefc/src/libcdio/driver/utf8.c#L170-L248

    А вы тут видите тут баг?

    j123123, 05 Июля 2017

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

    0

    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
    void SetTitleBarIcon(HWND hDlg)
    {
    	int i16, s16, s32;
    	HICON hSmallIcon, hBigIcon;
    
    	// High DPI scaling
    	i16 = GetSystemMetrics(SM_CXSMICON);
    	// Adjust icon size lookup
    	s16 = i16;
    	s32 = (int)(32.0f*fScale);
    	if (s16 >= 54)
    		s16 = 64;
    	else if (s16 >= 40)
    		s16 = 48;
    	else if (s16 >= 28)
    		s16 = 32;
    	else if (s16 >= 20)
    		s16 = 24;
    	if (s32 >= 54)
    		s32 = 64;
    	else if (s32 >= 40)
    		s32 = 48;
    	else if (s32 >= 28)
    		s32 = 32;
    	else if (s32 >= 20)
    		s32 = 24;
    
    	// Create the title bar icon
    	hSmallIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, s16, s16, 0);
    	SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hSmallIcon);
    	hBigIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, s32, s32, 0);
    	SendMessage (hDlg, WM_SETICON, ICON_BIG, (LPARAM)hBigIcon);
    }

    https://github.com/pbatard/rufus/blob/92d046e663811fd922262f1f347ad2ebe8e09b97/src/stdlg.c#L1607-L1639

    j123123, 05 Июля 2017

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    #include <stdio.h>;
    
    void check(int x, int y) {
      if (2*x == y && y < 0 && 0 <= 2*x) {
        puts("Impossible!");
      }
    }
    
    int main() {
      check(0x7F80007F, 0xFF0000FE);
    }

    https://runtimeverification.com/blog/?p=257
    When writing code for a specific compiler you can rely on the implementation-specified behavior, but signed overflow is still problematic. GCC promises that conversions between integer types will be reduced modulo the appropriate power of two when the value is not representable in the target type. This means that with GCC the conversion above will initialize var to -0x112234 on any architecture that GCC supports. However, only initialization and other conversions are safe. GCC still considers signed overflow in arithmetic as undefined behavior, and optimizes under the assumption that there will be no overflow. This can lead to apparently impossible results when signed values do overflow. Compiled with -O3, this program prints “Impossible!”.

    By adding apparently-redundant casts to 2*x to give (int)(2*(unsigned int)x), the calculation becomes implementation-specified behavior from an out-of-range conversion instead of undefined behavior. While this code may not be portable between compilers, GCC now guarantees the “impossible” code will not be executed even with -O3.

    j123123, 20 Июня 2017

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

    0

    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
    int r_k ( char *text, char *point, int d, int q ){
    
    	int n = strlen( text);
    	int m = strlen(point );
    	int h = (int) pow(d , m - 1   )  % q ;
    	int i;
    	int p = 0;
    	int t = 0;	
            int j ;
    	
    	for(i = 0  ;i  < m ; i++  ){
    			p = (  (d*p)  + point[i]) % q;
    			t = (  (d*t) +  text[i])  % q;
    		}
    	
    	for(i = 0;  i   <=  (n - m) ; i++   ){
    	
    		if(p  == t  ){
    	
    			for(j = 0 ; j < m  ; j++)
    	
    				if(  text[i + j]  !=  point[j]) 
    					break;
    	
    				if ( j == m  )
    						return i;
    					}
    	
    			t =   ( (  (d * (t - text[i] * h)   ) + (text[i + m])) % q )   + q ;
    		} 
    	return 0;
    	}

    Даже " Касперский" сказал что это говно и молча удалил.

    tyrin, 20 Июня 2017

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

    −1

    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
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
    	int num=0;
    	for(;num<99999999;++num)
    	{
    		if(num<10)
    		    fprintf(stdout, "0000000%d\n", num);
    		else if(num<100)
    		    fprintf(stdout,"000000%d\n", num);
    		else if(num<1000)
    		    fprintf(stdout, "00000%d\n", num);
    		else if(num<10000)
    		    fprintf(stdout, "0000%d\n", num);
    		else if(num<100000)
    		    fprintf(stdout, "000%d\n", num);
    		else if(num<1000000)
    		    fprintf(stdout, "00%d\n", num);
    		else if(num<10000000)
    		    fprintf(stdout, "0%d\n", num);
    	}
    }

    Генератор всех возможных пинов wps:D

    Masha-Rostova, 06 Июня 2017

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