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

    +144

    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
    #include <stdio.h>
    
    // Говнокод здесь
    #define ABS(x) ((x) ? (x) : (-(x)))
    
    int main () {
    	char ch = -128;
    	short sm = -32768;
    	int i = -2147483647; i--;                                    // здесь
    	long long l = -9223372036854775807LL; l--; // и здесь декременты нужны
    	                                                                             // для подавления варнингов
    	
    	printf("char:\t\tABS(%hhd) = %hhd\n", ch, ABS(ch));
    	printf("short:\t\tABS(%hd) = %hd\n", sh, ABS(sh));
    	printf("int:\t\tABS(%d) = %d\n", i, ABS(i));
    	printf("long long:\tABS(%lld) = %lld\n", l, ABS(l));
    
    	return 0;
    }

    Может быть, баян, но...
    Всем знакомый макрос ABS способен сделать большую гадость.
    Вот вывод программы:
    char: ABS(-128) = -128
    short: ABS(-32768) = -32768
    int: ABS(-2147483648) = -2147483648
    long long: ABS(-9223372036854775808) = -9223372036854775808

    whiskey, 12 Ноября 2010

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

    −344

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    NSInteger lengthString=[string length]-100;
    	for (NSInteger i=13000;i<lengthString;i++){ //ограничение поиска с начала, ищем пары ссылка - заголовок
    		if ([string characterAtIndex:i]=='<' &&
    			[string characterAtIndex:i+1]=='a' &&
    			[string characterAtIndex:i+2]==' ' && 
    			[string characterAtIndex:i+3]=='h' &&
    			[string characterAtIndex:i+4]=='r' && 
    			[string characterAtIndex:i+5]=='e' &&
    			[string characterAtIndex:i+6]=='f' && 
    			[string characterAtIndex:i+7]=='=') {
    			indexForUrl=i+16;
    		}

    парсинг ответа на поисковый запрос к Google...

    ниже еще пару сотен веток if

    realsugar, 12 Ноября 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    if (!bNextPageVisited)
    this->button(QWizard::NextButton)->setEnabled(false);
    if (bNextPageVisited)
    this->button(QWizard::NextButton)->setEnabled(true);

    Упячка мозга?..

    des-1008d, 12 Ноября 2010

    Комментарии (7)
  4. Java / Говнокод #4595

    +68

    1. 1
    2. 2
    3. 3
    if (url == null) {
     throw new RuntimeException("Error reading resource " + url.getFile());
    }

    ха.
    туториалы jogl

    Lure Of Chaos, 11 Ноября 2010

    Комментарии (13)
  5. Perl / Говнокод #4594

    −121

    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
    sub captcha {
    	my $msg = $_[0];
    	## make colors for validation image into hex again ##
    	$rgb_foreground =~ s/\#//g;
    	$rgb_shade =~ s/\#//g;
    	$rgb_background =~ s/\#//g;
    	$r_f = substr($rgb_foreground,0,2);
    	$g_f = substr($rgb_foreground,2,2);
    	$b_f = substr($rgb_foreground,4,2);
    	$r_s = substr($rgb_shade,0,2);
    	$g_s = substr($rgb_shade,2,2);
    	$b_s = substr($rgb_shade,4,2);
    	$r_b = substr($rgb_background,0,2);
    	$g_b = substr($rgb_background,2,2);
    	$b_b = substr($rgb_background,4,2);
    // Тут я вырезал кусок никчемного кода
    $ci{' '} = qq~
    .......
    .......
    .......
    .......
    .......
    .......
    .......
    .......
    .......
    .......
    ~;
    $ci{'!'} = qq~
    .......
    ...X...
    ...X...
    ...X...
    ...X...
    ...X...
    .......
    ...X...
    .......
    .......
    ~;
    $ci{'"'} = qq~
    .......
    ..X.X..
    ..X.X..
    ..X.X..
    .......
    .......
    .......
    .......
    .......
    .......
    ~;
    $ci{'#'} = qq~
    .......
    ..X.X..
    ..X.X..
    .XXXXX.
    ..X.X..
    .XXXXX.
    ..X.X..
    ..X.X..
    .......
    .......
    ~;
    $ci{'$'} = qq~
    .......
    ...X...
    ..XXXX.
    .X.X...
    ..XXX..
    ...X.X.
    .XXXX..
    ...X...
    .......
    .......
    ~;
    // Дальше идет вся таблица ASCII

    Вот таким вот образом выводили каптчу в далеком 2009 году. Очень надежный метод :)

    Arigato, 11 Ноября 2010

    Комментарии (16)
  6. C++ / Говнокод #4593

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    double *ptr = new (nothrow) double[n];
    if (ptr) {
    //....
    } else throw bad_alloc();

    Sanya_M, 11 Ноября 2010

    Комментарии (7)
  7. Perl / Говнокод #4592

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    sub generate_code {
    	my ($arrey_pos,$code);
    	my @arrey = ('a'..'q', 'C'..'O', '1'..'9', 'g'..'u', 'l'..'z', '9'..'1', 'H'..'W');
    
    	for (my $i = 0; $i < $_[0]; $i++) {
    		$arrey_pos = int(rand($#arrey));
    		$code .= $arrey[$arrey_pos];
    	}
    	$code;
    }

    Генерация кода.

    Arigato, 11 Ноября 2010

    Комментарии (17)
  8. Perl / Говнокод #4591

    −155

    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
    sub write_cookie {
    	my %params = @_;
    
    	if ($params{'-expires'} =~ /\+(\d+)m/) {
    		my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($date + $1 * 60);
    
    		$year += 1900;
    		my @mos = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    		my @dys = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
    		$mon  = $mos[$mon];
    		$wday = $dys[$wday];
    
    		$params{'-expires'} = sprintf("%s, %02i-%s-%04i %02i:%02i:%02i GMT", $wday, $mday, $mon, $year, $hour, $min, $sec);
    	}
    
    	$params{'-path'}    = " path=$params{'-path'};"       if $params{'-path'};
    	$params{'-expires'} = " expires=$params{'-expires'};" if $params{'-expires'};
    
    	"$params{'-name'}=$params{'-value'};$params{'-path'}$params{'-expires'}";
    }

    setcookie() Perl-вариант.

    Arigato, 11 Ноября 2010

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

    +130

    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
    if ((!(((constmonth == 1) && (Finalday > 31))
    || ((constmonth == 2) && (Finalyear % 4 == 0) && (Finalday > 29))
    || ((constmonth == 2) && (Finalyear % 4 != 0) && (Finalday> 28))
    || ((constmonth == 3) && (Finalday > 31))
    || ((constmonth == 4) && (Finalday > 30))
    || ((constmonth == 5) && (Finalday > 31))
    || ((constmonth == 6) && (Finalday > 30))
    || ((constmonth == 7) && (Finalday > 31))
    || ((constmonth == 8) && (Finalday > 31))
    || ((constmonth == 9) && (Finalday > 30))
    || ((constmonth == 10) && (Finalday > 31))
    || ((constmonth == 11) && (Finalday > 30))
    || ((constmonth == 12) && (Finalday > 31))))
    && ((((constmonth + 1 == 1) && (Finalday > 31))
    || ((constmonth + 1 == 2) && (Finalyear % 4 == 0) && (Finalday > 29))
    || ((constmonth + 1 == 2) && (Finalyear % 4 != 0) && (Finalday > 28))
    || ((constmonth + 1 == 3) && (Finalday > 31))
    || ((constmonth + 1 == 4) && (Finalday > 30))
    || ((constmonth + 1 == 5) && (Finalday > 31))
    || ((constmonth + 1 == 6) && (Finalday > 30))
    || ((constmonth + 1 == 7) && (Finalday > 31))
    || ((constmonth + 1 == 8) && (Finalday > 31))
    || ((constmonth + 1 == 9) && (Finalday > 30))
    || ((constmonth + 1 == 10) && (Finalday > 31))
    || ((constmonth + 1 == 11) && (Finalday > 30))
    || ((constmonth + 1 == 12) && (Finalday > 31)))))
    {
    if ((constmonth + 1 == 2) && (Finalyear % 4 == 0)) { Finalday = 29; }
    if ((constmonth + 1 == 2) && (Finalyear % 4 != 0)) { Finalday = 28; }
    
    switch (constmonth + 1)
    {
    case 1: Finalday = 31; break;
    case 3: Finalday = 31; break;
    case 4: Finalday = 30; break;
    case 5: Finalday = 31; break;
    case 6: Finalday = 30; break;
    case 7: Finalday = 31; break;
    case 8: Finalday = 31; break;
    case 9: Finalday = 30; break;
    case 10: Finalday = 31; break;
    case 11: Finalday = 30; break;
    case 12: Finalday = 31; break;
    }
    //constmonth++;

    GreBer, 11 Ноября 2010

    Комментарии (10)
  10. Perl / Говнокод #4589

    −119

    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
    sub mainMenu {
    	if ($action eq "addtab" && $iamadmin) { require "$sourcedir/AdvancedTabs.pl"; &AddNewTab; }
    	elsif ($action eq "edittab" && $iamadmin) { require "$sourcedir/AdvancedTabs.pl"; &EditTab; }
    	elsif ($action ne "") {
    		if ($action eq "search2") {
    			$tmpaction = "search";
    		} elsif ($action eq "favorites" || $action eq "shownotify" || $action eq "im" || $action eq "imdraft" || $action eq "imoutbox" || $action eq "imstorage" || $action eq "imsend" || $action eq "imsend2" || $action eq "imshow" || $action eq "profileCheck" || $action eq "myviewprofile" || $action eq "myprofile" || $action eq "myprofileContacts" || $action eq "myprofileOptions" || $action eq "myprofileBuddy" || $action eq "myprofileIM" || $action eq "myprofileAdmin" || $action eq "myusersrecentposts") {
    			$tmpaction = "mycenter";
    		} elsif ($action eq "messagepagetext" || $action eq "messagepagedrop" || $action eq "threadpagetext" || $action eq "threadpagedrop" || $action eq "post" || $action eq "notify" || $action eq "boardnotify" || $action eq "sendtopic" || $action eq "modify") {
    			$tmpaction = "home";
    		} elsif ($action eq "guestpm2") {
    			$tmpaction = "guestpm";
    		} else { $tmpaction = $action; }
    
    	} else {
    		$tmpaction = "home";
    	}
    
    	$tab{'home'} = qq~<span |><a href="$scripturl" title = "$img_txt{'103'}" style="padding: 3px 0 4px 0;">$tabfill$img_txt{'103'}$tabfill</a></span>~;
    	$tab{'help'} = qq~<span |><a href="$scripturl?action=help" title = "$img_txt{'119'}" style="padding: 3px 0 4px 0; cursor:help;">$tabfill$img_txt{'119'}$tabfill</a></span>~;
    	if ($maxsearchdisplay > -1) {
    		$tab{'search'} = qq~<span |><a href="$scripturl?action=search" title = "$img_txt{'182'}" style="padding: 3px 0 4px 0;">$tabfill$img_txt{'182'}$tabfill</a></span>~;
    	}
    	if (!$ML_Allowed || ($ML_Allowed == 1 && !$iamguest) || ($ML_Allowed == 2 && $staff) || ($ML_Allowed == 3 && ($iamadmin || $iamgmod))) {
    		$tab{'ml'} = qq~<span |><a href="$scripturl?action=ml" title = "$img_txt{'331'}" style="padding: 3px 0 4px 0;">$tabfill$img_txt{'331'}$tabfill</a></span>~;
    	}
    	if ($iamadmin) {
    		$tab{'admin'} = qq~<span |><a href="$boardurl/AdminIndex.$yyaext" title = "$img_txt{'2'}" style="padding: 3px 0 4px 0;">$tabfill$img_txt{'2'}$tabfill</a></span>~;
    	}
    	if ($iamgmod) {
    		if (-e "$vardir/gmodsettings.txt") { require "$vardir/gmodsettings.txt"; }
    		if ($allow_gmod_admin) {
    			$tab{'admin'} = qq~<span |><a href="$boardurl/AdminIndex.$yyaext" title = "$img_txt{'2'}" style="padding: 3px 0 4px 0;">$tabfill$img_txt{'2'}$tabfill</a></span>~;
    		}
    	}
    	if ($sessionvalid == 0 && !$iamguest) {
    		my $sesredir;
    		unless (!$testenv || $action eq "revalidatesession" || $action eq "revalidatesession2") {
    			$sesredir = $testenv;
    			$sesredir =~ s/\=/\~/g;
    			$sesredir =~ s/;/x3B/g;
    			$sesredir = qq~;sesredir=$sesredir~;
    		}
    		$tab{'revalidatesession'} = qq~<span |><a href="$scripturl?action=revalidatesession$sesredir" title = "$img_txt{'34a'}" style="padding: 3px 0 4px 0;">$tabfill$img_txt{'34a'}$tabfill</a></span>~;
    	}
    
    // далее мало что меняется в стиле...

    Формируем меню...

    Arigato, 11 Ноября 2010

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