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

    +138

    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
    int fermat (void)
    {
      const int MAX = 1000;
      int a=1,b=1,c=1;
      while (1) {
        if (((a*a*a) == ((b*b*b)+(c*c*c)))) return 1;
        a++;
        if (a>MAX) {
          a=1;
          b++;
        }
        if (b>MAX) {
          b=1;
          c++;
        }      
        if (c>MAX) {
          c=1;
        }
      }
      return 0;
    }
    
    #include <stdio.h>
    
    int main (void)
    {
      if (fermat()) {
        printf ("Fermat's Last Theorem has been disproved.\n");
      } else {
        printf ("Fermat's Last Theorem has not been disproved.\n");
      }
      return 0;
    }

    Fermat's Last Theorem has been disproved
    http://blog.regehr.org/archives/140

    Если уже было черкните мне на /dev/null@localhost, удалю

    Elvenfighter, 11 Декабря 2014

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

    +136

    1. 1
    2. 2
    /* To the unenlightened: This sets the 20 MSBs to 0 for sanity's sake. */
    return four_bytes_to_uint32(four_byte_array) & ~(~0 << 12);

    Так приказали K&R.

    codemonkey, 10 Декабря 2014

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

    +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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    char* xml_compose_simple_response(char* response, int code, char* description, char* additional_data)
    {
    	size_t resp_length = 0;
    	char* buff = NULL;
    
    	resp_length += strlen(RESPONSE_HEADER_PREFIX);
    	resp_length += strlen(session_type);
    	resp_length += strlen(transaction_id);
    	resp_length += strlen(response) + strlen(EMPTY_TAG);
    	if(NULL != additional_data)
    	{
    		resp_length += strlen(additional_data);
    	}
    	resp_length += strlen(description) + strlen(RESULT_INT) + sizeof(int) * 8;
    	resp_length += strlen(RESPONSE_HEADER_SUFFIX);
    
    	resp_length += 1;
    
    	if(NULL != (buff = malloc(resp_length)))
    	{
    		buff[0] = '\0';
    
    		sprintf(buff, RESPONSE_HEADER_PREFIX""EMPTY_TAG, session_type, transaction_id, response);
    
    		if (additional_data != NULL)
    		{
    			char tmp_desc[_2K];
    			sprintf(tmp_desc, description, additional_data);
    
    			sprintf(&buff[strlen(buff)], RESULT_INT, code, tmp_desc);
    		}
    		else
    		{
    			sprintf(&buff[strlen(buff)], RESULT_INT, code, description);
    		}
    		strcat(buff, RESPONSE_HEADER_SUFFIX);
    	}
    	else
    	{
    		mng_report_memory_failure_location_and_exit();
    	}
    	return buff;
    }

    XML вручную собирай @ на кавычкай падай. Никакого АПИ, только хардкор.

    codemonkey, 07 Декабря 2014

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

    +135

    1. 1
    return (true == is_break) ? resource : NULL;

    Вонъ изъ профессiи!

    codemonkey, 07 Декабря 2014

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

    +131

    1. 1
    2. 2
    // bg_pmove.c -- both games player movement code
    // takes a playerstate and a usercmd as input and returns a modifed playerstate

    Дальше идут 11 тысяч строк нечитаемого говна. Это вообще нормально?!

    gost, 03 Декабря 2014

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

    +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
    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
    int Sys_FunctionCmp(void *f1, void *f2) {
    
    	int i, j, l;
    	byte func_end[32] = {0xC3, 0x90, 0x90, 0x00};
    	byte *ptr, *ptr2;
    	byte *f1_ptr, *f2_ptr;
    
    	ptr = (byte *) f1;
    	if (*(byte *)ptr == 0xE9) {
    		//Com_Printf("f1 %p1 jmp %d\n", (int *) f1, *(int*)(ptr+1));
    		f1_ptr = (byte*)(((byte*)f1) + (*(int *)(ptr+1)) + 5);
    	}
    	else {
    		f1_ptr = ptr;
    	}
    	//Com_Printf("f1 ptr %p\n", f1_ptr);
    
    	ptr = (byte *) f2;
    	if (*(byte *)ptr == 0xE9) {
    		//Com_Printf("f2 %p jmp %d\n", (int *) f2, *(int*)(ptr+1));
    		f2_ptr = (byte*)(((byte*)f2) + (*(int *)(ptr+1)) + 5);
    	}
    	else {
    		f2_ptr = ptr;
    	}
    	//Com_Printf("f2 ptr %p\n", f2_ptr);
    
    #ifdef _DEBUG
    	sprintf((char *)func_end, "%c%c%c%c%c%c%c", 0x5F, 0x5E, 0x5B, 0x8B, 0xE5, 0x5D, 0xC3);
    #endif
    	for (i = 0; i < 1024; i++) {
    		for (j = 0; func_end[j]; j++) {
    			if (f1_ptr[i+j] != func_end[j])
    				break;
    		}
    		if (!func_end[j]) {
    			break;
    		}
    	}
    #ifdef _DEBUG
    	l = i + 7;
    #else
    	l = i + 2;
    #endif
    	//Com_Printf("function length = %d\n", l);
    
    	for (i = 0; i < l; i++) {
    		// check for a potential function call
    		if (*((byte *) &f1_ptr[i]) == 0xE8) {
    			// get the function pointers in case this really is a function call
    			ptr = (byte *) (((byte *) &f1_ptr[i]) + (*(int *) &f1_ptr[i+1])) + 5;
    			ptr2 = (byte *) (((byte *) &f2_ptr[i]) + (*(int *) &f2_ptr[i+1])) + 5;
    			// if it was a function call and both f1 and f2 call the same function
    			if (ptr == ptr2) {
    				i += 4;
    				continue;
    			}
    		}
    		if (f1_ptr[i] != f2_ptr[i])
    			return qfalse;
    	}
    	return qtrue;
    }

    Хмм...

    gost, 03 Декабря 2014

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

    +132

    1. 1
    2. 2
    3. 3
    #ifndef M_PI
    #define M_PI		3.14159265358979323846f	// matches value in gcc v2 math.h
    #endif

    Сишкопроблемы.

    gost, 03 Декабря 2014

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

    +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
    bool findImageToleranceIn(CTSInfo *info, bitmap *imageToFind, int32_t *x, int32_t *y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t tolerance)
    {
        int I, J, XX, YY;
        info->tol = tolerance;
        int dX = (x2 - x1) - (imageToFind->width - 1);
        int dY = (y2 - y1) - (imageToFind->height - 1);
        for (I = 0; I < dY; ++I)
        {
            for (J = 0; J < dX; ++J)
            {
                for (YY = 0; YY < imageToFind->height; ++YY)
                {
                    for (XX = 0; XX < imageToFind->width; ++XX)
                    {
                        rgb32* pixel = &imageToFind->pixels[YY * imageToFind->width + XX];
                        rgb32* targetPixel = &info->targetImage->pixels[(YY + I) * info->targetImage->width + (XX + J)];
                        if (pixel->a != 0)
                        {
                            if (!(*info->ctsFuncPtr)(info, pixel, targetPixel))
                            {
                                goto Skip;
                            }
                        }
                    }
                }
                *x = J + x1;
                *y = I + y1;
                return true;
                Skip:
                continue;
            }
        }
        *x = -1;
        *y = -1;
        return false;
    }

    В чём здесь сакральный смысл GoTo?

    Cynicrus, 01 Декабря 2014

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

    +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
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    bool bitmap_to_24bit_string(bitmap *bmp, char **str, uint32_t *len)
    {
        if (!bmp || !bmp->pixels)
        return false;
        int I, J;
        uint32_t size = ((bmp->width * 24 + 31) / 32) * 4 * bmp->height;
        rgb24 *pixels = malloc(size);
        if (pixels)
        {
            for (I = 0; I < bmp->height; ++I)
            {
                for (J = 0; J < bmp->width; ++J)
                {
                    pixels[I * bmp->width + J].b = bmp->pixels[I * bmp->width + J].r;
                    pixels[I * bmp->width + J].g = bmp->pixels[I * bmp->width + J].g;
                    pixels[I * bmp->width + J].r = bmp->pixels[I * bmp->width + J].b;
                }
            }
            uint32_t destlen = compressBound(size);
            *str = malloc(destlen);
            if (*str)
            {
                if (compress((Bytef *)*str, (uLongf *)&destlen, (Bytef *)pixels, size) == Z_OK)
                {
                    free(pixels);
                    pixels = NULL;
                    char *b64str;
                    uint32_t b64_len;
                    if (base64encode((const uint8_t *)*str, destlen, &b64str, &b64_len))
                    {
                        free(*str);
                        *str = b64str;
                        *len = b64_len + 2;
                        b64str = malloc(*len);
                        if (b64str)
                        {
                            b64str[0] = 'm';
                            strncpy(&b64str[1], *str, b64_len);
                            free(*str);
                            *str = b64str;
                            (*str)[b64_len + 1] = '';
                            return true;
                        }
                    }
                }
                free(*str);
                *len = 0;
                *str = NULL;
            }
            free(pixels);
        }
        return false;
    }

    Ещё подкину в общую копилку

    Cynicrus, 01 Декабря 2014

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

    +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
    char *stringFromDTM(MDTM *dtm)
    {
        if (dtm->count < 1)
        return "";
        uint32_t size = (sizeof(MDTMPoint) + sizeof(uint32_t)) * dtm->count;
        void *data = calloc(1, size);
        uint32_t *ptr = data;
        *(ptr++) = size;
        uint32_t index;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].x;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].y;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].color;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].tol;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].size;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].x;
        bool *bptr = (bool *)ptr;
        for (index = 0; index < dtm->count; index++)
        *(bptr++) = dtm->points[index].bad;
        uint32_t len = compressBound(size);
        char *buffer = malloc(len);
        if (compress((Bytef *)buffer, (uLongf *)&len, data, size) == Z_OK)
        {
            free(data);
            char *compressed = malloc(len + sizeof(uint32_t));
            *((uint32_t *)(compressed)) = len;
            strcpy(compressed + sizeof(uint32_t), buffer);
            free(buffer);
        }
        free(buffer);
        free(data);
        return "";
    }

    Я так и не раскурил, почему так, а не иначе.

    Cynicrus, 01 Декабря 2014

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