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

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // Делаем из префикса количество хостов (без .0 и броадкаста)
    numips = pow(2.0, (double)(32 - slashnet)) - 2;
    
    // Делаем префикс из маски сети
    slashnet = 32 - ((int)log2((double)(0xFFFFFFFF - vnetconfig->nm)) + 1);

    Всё те же, всё оттуда же...

    raorn, 12 Мая 2010

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

    +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
    int check_process(pid_t pid, char *search) {
      char file[1024], buf[1024];
      FILE *FH=NULL;
      int rc, ret=0;
    
      snprintf(file, 1024, "/proc/%d/cmdline", pid);
      rc = check_file(file);
      if (!rc) {
        // cmdline exists
        ret = 1;
        if (search) {
          // check if cmdline contains 'search'
          FH = fopen(file, "r");
          if (FH) {
    	bzero(buf, 1024);
    	while(fgets(buf, 1024, FH)) {
    	  char *p;
    	  while((p = memchr(buf, '\0', 1024))) {
    	    *p = 'X';
    	  }
    	  buf[1023] = '\0';
    	  if (strstr(buf, search)) {
    	    ret = 0;
    	  }
    	}
    	fclose(FH);
          }
        } else {
          ret = 0;
        }
      } else {
        ret = 1;
      }
      return(ret);
    }

    Суровые калифорнийские студенты суровы.

    raorn, 11 Мая 2010

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (init) {
    } else {
      // thread is not initialized, run first time local state setup
      ...
    }

    raorn, 11 Мая 2010

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    memset( fc->key, 0, KEY_LEN+1);
    memset( fc->value, 0, VALUE_LEN+1);
    
    strncpy(fc->key, key, strlen( key) + 1);
    strncpy(fc->value, value,strlen( value) + 1);

    совершенное непонимание работы ф-ии strncpy

    benderlog, 30 Апреля 2010

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

    +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
    #define alias long
    #define int b
    #define cat 2
    alias int=cat;
    #undef int
    
    int a$(int b)
    {
      return 1;
    }
    
    main()
    {
      return a$(b)+1;
    }

    Здесь нет С++, зато есть... bash!
    На что спорим, что код возврата программы будет 1?

    nil, 05 Февраля 2010

    Комментарии (19)
  7. C# / Говнокод #2118

    +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
    public string generateEMail()
    		{
    			string res;
    			int i = PersonName.IndexOf(" ");
    			char[] str1 = new char[i];
    			PersonName.CopyTo(0, str1, 0, i);
    			string str11 = new string(str1);
    			char[] str2 = new char[PersonName.Length - i - 1];
    			PersonName.CopyTo(i + 1, str2, 0, PersonName.Length - i - 1);
    			string str22 = new string(str2);
    			res = str11.ToString() + "." + str22.ToString();
    			if (res.Length > 20)
    			{
    				str1 = new char[20];
    				res.CopyTo(0, str1, 0, 20);
    				res = new string(str1);
    			}
    			res += "@domain.ua";
    			return res;
    		}

    Вот вам шаблон для получения емейла из имени и фамилии сотрудника.

    Woonder, 10 Ноября 2009

    Комментарии (9)
  8. C# / Говнокод #1751

    +136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /// <summary>Read-Only property. Gets the Age.</summary>
    public Int32 Age {
    	get {
    		Int32 age = 0;
    		if(this.dateOfBirth != DateTime.MaxValue){
    			String temp = (DateTime.Now.Subtract(this.dateOfBirth).TotalDays / 365).ToString();
    			age = Convert.ToInt32(temp.Substring(0, temp.IndexOf(".")));
    		}
    		return (age);
    	}
    }

    вот только одно не понимаю -- мочему Int32?

    OlgaWolga, 02 Сентября 2009

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public bool IsPositiveNumber(String strNumber)
    {
        Regex objNotPositivePattern = new Regex("[^0-9.]");
        Regex objPositivePattern = new Regex("^[.][0-9]+$|[0-9]*[.]*[0-9]+$");
        Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
        return !objNotPositivePattern.IsMatch(strNumber) &&
        objPositivePattern.IsMatch(strNumber) &&
        !objTwoDotPattern.IsMatch(strNumber);
    }

    Валидатор :)

    Coffeeholic, 01 Сентября 2009

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

    +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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    #include <stdio.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <math.h>
    #include <stdlib.h>
    
    struct thread_arg
    {
    	int a;
    	int b;
    	int c;
    	double d;
    };
    	
    
    void *ret_x1(void *arg)
    {
    		
    	struct thread_arg targ = *(struct thread_arg *)arg;
    	double x1;
    	x1 = (-targ.b + sqrt(targ.d)) / (2*targ.a);
    
    	fprintf(stderr, "x1 = %f\n", x1);
    
    	return NULL;
    }
    
    void *ret_x2(void *arg)
    {
    	struct thread_arg targ = *(struct thread_arg*)arg;
    	double x2;
    	x2 = (-targ.b - sqrt(targ.d)) / (2*targ.a);
    
    	
    
    	fprintf(stderr, "x2 = %f\n", x2);
    	
    	return NULL;
    }
    
    int main(void)
    {
    	pthread_t thread1, thread2;
    	struct thread_arg args;
    
    	fprintf(stderr, "Enter a, b and c\n");
    	scanf("%d %d %d", &args.a, &args.b, &args.c);
    	
    	args.d = args.b*args.b - 4*args.a*args.c;
    
    	if(args.d < 0)
    	{
    		fprintf(stderr,"There is no roots\n");
    		return 0;
    	}
    	else
    	{
    		if(pthread_create(&thread1, NULL, &ret_x1, &args) != 0)
    		{
    			fprintf(stderr, "Error1\n");
    			return 1;
    		}
    		if(pthread_create(&thread2, NULL, &ret_x2, &args) != 0)
    		{
    			fprintf(stderr, "Error2\n");
    			return 1;
    		}
    		pthread_join(thread1, NULL);
    		pthread_join(thread2, NULL);
    
    	}
    	return 0;
    		
    }

    Многопоточное решение квадратного уравнения...

    zitzy, 16 Августа 2009

    Комментарии (11)
  11. PHP / Говнокод #1126

    +136

    1. 1
    2. 2
    вавап
    о

    вап

    guest, 02 Июня 2009

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