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

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

    +136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int num10 = Convert.ToInt16(this.label13.Text);
        int num11 = Convert.ToInt16(this.label11.Text);
        int num12 = Convert.ToInt16(this.LH2.Text);
        int num13 = Convert.ToInt16(this.dmserver.Text);
        int num14 = Convert.ToInt16(this.vipserver.Text);
        int num15 = Convert.ToInt16(this.NAMALSK_FREE_server.Text);
        int num16 = Convert.ToInt16(this.Igromafia_serevr.Text);
        int num18 = Convert.ToInt16(this.LH3_total_on_off.Text);
        int num17 = ((((((num10 + num11) + num13) + num14) + num15) + num12) + num16) + num18;
        this.servers.Text = Convert.ToString(num17);

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

    kingmonstr, 03 Января 2015

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

    +136

    1. 1
    2. 2
    Prelude> [(-1/0),1 .. 1]
    [-Infinity,1.0,Infinity,Infinity]

    Целых 2 бесконечности между единицей.

    Abbath, 22 Декабря 2014

    Комментарии (6)
  4. Си / Говнокод #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)
  5. Си / Говнокод #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)
  6. Си / Говнокод #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)
  7. Си / Говнокод #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)
  8. C# / Говнокод #17105

    +136

    1. 1
    2. 2
    3. 3
    public override string GetMobileBody() {
    	return System.Text.Encoding.UTF8.GetString(new Terrasoft.Common.CompressionUtilities().UnZip(new byte[] { 31,139,8, /*... over 9000 bytes ...*/,36,59,0,0 }));
    }

    По долгу службы пришлось столкнуться с одной небезызвестной CRM отечественного производства.
    Безумно интересен сакральный смысл такого кода.

    lorond, 13 Ноября 2014

    Комментарии (29)
  9. Куча / Говнокод #17078

    +136

    1. 1
    2. 2
    -#location=Location
    +location=Localisation

    Прилетел коммит с обновлением французской локализации, а там такое.

    someone, 07 Ноября 2014

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

    +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
    DIR_STRUCT * fill_dir_struct(DIR_STRUCT * dir_stc, _ptr_by_val_(char *) base_dir_path, _ptr_by_val_(char *) offset_dir)
    {
    	DIR_STRUCT * 		sub_dir;
    	DIR * 				srcdir;
    	struct 				stat st;
    	char 				full_sub_dir_path[MAX_PATH_SIZE];
    	struct dirent * 	dent;
    
    	sprintf(full_sub_dir_path, "%s/%s", base_dir_path, offset_dir);
    	dbgprintln("Directory %s", full_sub_dir_path);
    
    	if(NULL != (dir_stc = malloc(sizeof(DIR_STRUCT))))
    	{
    		memset(dir_stc, 0x00, sizeof(DIR_STRUCT));
    		if (NULL != (srcdir = opendir(full_sub_dir_path)))
    		{
    			if(NULL != (dir_stc->dir_path = malloc(strlen(offset_dir) + 1)))
    			{
    				strcpy(dir_stc->dir_path, offset_dir);
    				for( ;(NULL != (dent = readdir(srcdir))); )
    				{
    					if((0 != strcmp(dent->d_name, ".")) &&
    					   (0 != strcmp(dent->d_name, "..")) &&
    					   (0 <= fstatat(dirfd(srcdir), dent->d_name, &st, 0)))
    					{
    						if (S_ISDIR(st.st_mode)) //Directory
    						{
    							if(NULL != (sub_dir = fill_dir_struct(sub_dir, full_sub_dir_path, dent->d_name)))
    							{
    								dir_stc->sub_dirs 		 	  = list_append_node(dir_stc->sub_dirs, sub_dir);
    								dir_stc->dir_files_size 	 += sub_dir->dir_files_size;
    								dir_stc->sub_dir_files_count += sub_dir->sub_dir_files_count;
    							}
    							else
    							{
    								dir_stc = destroy_dir_struct(dir_stc);
    								break;
    							}
    						}
    						else 					//File
    						{
    							dbgprintln("File %s, size %lu bytes", dent->d_name, st.st_size);
    							dir_stc->dir_files 		 	 = list_append_node(dir_stc->dir_files, allocate_and_copy_char_buffer(dent->d_name, strlen(dent->d_name) + 1));
    							dir_stc->dir_files_size 	+= st.st_size;
    							dir_stc->sub_dir_files_count++;
    						}
    					}
    				}//End of for(;NULL != (dent = readdir(srcdir)); )
    				closedir(srcdir);
    			}
    			else//End of if(NULL != (dir_stc->dir_path = malloc(strlen(offset_dir) + 1)))
    			{
    				dir_stc = destroy_dir_struct(dir_stc);
    			}
    		}//End of if (NULL != (srcdir = opendir(full_sub_dir_path)))
    		else
    		{
    			dir_stc = destroy_dir_struct(dir_stc);
    		}
    	}//End of if(NULL != (dir_stc = malloc(sizeof(DIR_STRUCT))))
    
    	return dir_stc;
    }

    Восьмикратный индент, Йода нотейшн, const *(x) const в аргументах. Есть подозрение, что велосипедисты не знали о scandir.

    Это кладезь говна.

    codemonkey, 08 Октября 2014

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

    +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
    class Program
        {        
            class A
            {
    
                //-----------------------------------------------------------------------
                public static A CurrentRoot;
                public static Dictionary<object, A> RootMap = new Dictionary<object, A>();
                public static object Lock = new object();
                //-----------------------------------------------------------------------
    
                public int Test;
    
                public A()
                {
                    lock (Lock)
                    {
                        CurrentRoot = this; 
                        b = new B();
                    }   
                }   
                internal class B
                {
                    public B() { RootMap.Add(this, CurrentRoot); }
    
                    public A root { get { return RootMap[this]; } }                
    
                    ~B() { RootMap.Remove(this); }                
                }
                public B b;
            }
         
            static void Main(string[] args)
            {
    
                A a1 = new A(); a1.Test = 555;
                A a2 = new A(); a2.Test = 888;
    
                Console.WriteLine(a1.b.root.Test); Console.WriteLine(a1.Test);
                Console.WriteLine(a2.b.root.Test); Console.WriteLine(a2.Test);
    
    
                Console.WriteLine(a1.b.root.b.root.b.root.b.root.b.root.Test);
            }

    Класс создан для того чтобы вложенные структуры имели доступ к структуре родителя. Safe thread support.

    maxillion, 20 Сентября 2014

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