1. Си / Говнокод #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)
  2. Java / Говнокод #23142

    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
    35. 35
    36. 36
    37. 37
    38. 38
    import java.util.*;
    
    public class Main
    {
    	public static void main(String[] args)
    	{
    		two s = new two(25);
    		s.get();
    	}
    }
    
    class one
    {
    	private int a;
    	
    	one(int a)
    	{
    		this.a = a*2;
    	}
    	
    	void get()
    	{
    		System.out.println(a);
    	}
    }
    
    class two extends one
    {
    	void get()
    	{
    		get();
        }
    	
    	two(int a)
    	{
    		super(a);
    	}
    }

    Когда пытаешься вызвать функцию подкласса из класса

    blondi, 20 Июня 2017

    Комментарии (3)
  3. bash / Говнокод #23141

    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
    #!/system/bin/bash
    
    indexOf()
    {
    echo "$1" "$2" | awk '{print index($1,$2)}'
    }
    
    str=$(wget -q -O - http://quote-citation.com/random)
    
    str=${str//\"/} #??????? ???????
    str=${str//\'/}
    
    indexOf "$str" "inner"

    Вот хуй поймёшь что хотели написать в этом коде

    blondi, 20 Июня 2017

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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    for (int i = 0; i < components.Length; i++) 
    { 
              if (components[i]) components[i].GetComponent<ComponentScript>().ChangeComponent(CalculateCircuitScript.ComponentDataArray[components[i].GetComponent<ComponentScript>().lineNumber, components[i].GetComponent<ComponentScript>().elementNumber]); 
    }

    Конструктор трёхфазных цепей на Unity3D

    Super_Indus_coding, 19 Июня 2017

    Комментарии (0)
  6. Pascal / Говнокод #23137

    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
    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
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    procedure TForm1.ProcListAdvancedCustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
      var DefaultDraw: Boolean);
    var
      TP:TprocessInfo;
      xColor: TColor;
      xRect: TRect;
      xBitmap: TBitmap;
      I, L, R: Integer;
    begin
      DefaultDraw:=False;
      TP:=TProcessInfo(Item.SubItems.Objects[0]);
      if (Item.Selected) then
      begin
        if Sender.Focused then
        begin
          if (FItemAtCursor <> -1) and (Item.Index = FItemAtCursor) then
            xColor:=clNavy
          else
            xColor:=$00C56A31;
        end
        else
          xColor:=$00D8E9EC
      end
      else
      begin
        if (TP.New<2) or (TP.Terminated<2) or (TP.Hidden) then
        begin
    
          if ShowDangerousProcesses then
          if TP.Hidden then
          xColor:=$00DBDBDB;
    
          if ShowNewProcesses then
          if TP.New <2 then
          xColor:=$001DEB2D;
    
          if ShowTerminatedProcesses then
          if TP.Terminated < 2 then
          xColor:=$001D2DEB;
        end
        else
    
        if (Item.Index mod 2 = 1) then
        xColor:=RGB(245,245,255)
        else
        xColor:=clWindow;
      end;
      Sender.Canvas.Brush.Color:=xColor;
      DefaultDraw:=True;
    
      if (Item.Selected) and Sender.Focused
      then Sender.Canvas.Font.Color:=clWindow
      else Sender.Canvas.Font.Color:=clWindowText;
      Sender.Canvas.FillRect(Item.DisplayRect(drLabel));
      DefaultDraw:=True;
    
      Exit; 
    
      xRect:=Item.DisplayRect(drLabel);
      Sender.Canvas.TextRect(xRect,xRect.Left+2,xRect.Top,Item.Caption);
    
      for I:=0 to TListView(Sender).Columns.Count-1 do
      begin
        if TListView(Sender).Columns[TListView(Sender).Columns[I].ID].Width<=0 then Continue;
        if (I=0) and (TListView(Sender).Columns[I].ID <> 0) then
        begin
          xRect.Left:=0;
          xRect.Right:=xRect.Left+TListView(Sender).Columns.Items[TListView(Sender).Columns[I].ID].Width-1;
          Sender.Canvas.FillRect(xRect);
          Sender.Canvas.TextRect(xRect,xRect.Left+2,xRect.Top,Item.SubItems[TListView(Sender).Columns[I].ID-1]);
        end
        else
        begin
        if I>0 then
        begin
          xRect.Left:=xRect.Right+1;
          xRect.Right:=xRect.Left+TListView(Sender).Columns.Items[TListView(Sender).Columns[I].ID].Width-1;
          Sender.Canvas.FillRect(xRect);
          if TListView(Sender).Columns[I].ID >0 then
          Sender.Canvas.TextRect(xRect,xRect.Left+5,xRect.Top,Item.SubItems[Pred(TListView(Sender).Columns[I].ID)])
          else
          begin
            L:=(Item.DisplayRect(drIcon).Right-Item.DisplayRect(drIcon).Left)+6;
          Sender.Canvas.TextRect(xRect,xRect.Left+L,xRect.Top, Item.Caption)
        end;
        end;
    
        end;
      end;
      Sender.Canvas.Brush.Color:=clWindow;
      Sender.Canvas.FillRect(Item.DisplayRect(drIcon));
      if Item.ImageIndex=-1 then Exit;
      xBitmap:=TBitmap.Create;
      TListView(Sender).SmallImages.GetBitmap(Item.ImageIndex,xBitmap);

    ListView - великий и ужасный! - в режиме OwnerDraw.
    Писал диспетчер процессов. Когда я разрешил прятать столбцы и включил свойство FullDrag, моя жизнь круто изменилась.

    antipattern, 19 Июня 2017

    Комментарии (3)
  7. PHP / Говнокод #23134

    +2

    1. 1
    return ( empty( $syndication_meta ) ? false : true );

    ldv_a, 16 Июня 2017

    Комментарии (0)
  8. Java / Говнокод #23132

    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
    import java.util.*;
    
    
    public class Main
    {
    	public static void main(String[] args) throws InterruptedException
    	{
    		StringBuilder s = new StringBuilder("#");
    		byte a=1;
    		boolean t=false;
    		while(true)
    		{
    			if(!t)
    			{
    				s.append("#");
    				a++;
    			}
    			if(a==40)
    			{
    				t=true;
    			}
    			if(a==0)
    			    t=false;
    			if(t)
    			{
    				s.deleteCharAt(s.length()-1);
    				a--;
    			}
    			System.out.println(s);
    			Thread.sleep(100);
    		}
    	}
    }

    Красиво зато вышло

    Anineshnica, 15 Июня 2017

    Комментарии (0)
  9. PHP / Говнокод #23131

    +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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    public function sql ($sql) {
    	$r = array(
    		"'" => "", //ору с этого
    		'"' => '',
    		'DROP' => '',
    		'TRUNCATE' => '',
    		'SELECT' => '',
    		'UPDATE' => '',
    		'INSERT' => '',
    		'DELETE' => '',
    		'INSERT' => '',
    		'UNION' => ''
    	);
    
    	if($this->strposa(strtoupper($sql), array_keys($r))){
    		mail('[email protected]', 'Внимание!', 'Обнаружена попытка SQL инъекции: "'.$sql.'" с IP адреса: '.$_SERVER['REMOTE_ADDR']);
    	}
    
    	$sql = str_ireplace(array_keys($r), $r, $sql);
    	$sql = htmlspecialchars($sql);
    	$sql = strip_tags($sql);
    	$sql = stripslashes($sql);
    
    	return $sql;
    }

    enly1, 14 Июня 2017

    Комментарии (6)
  10. PHP / Говнокод #23130

    −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
    public function sendChat ($msg) {
    	if($this->isLogged()){
    		if($this->checkAd($this->sql($msg)) !== '' || $this->checkAd($this->sql($msg))[0] !== ' '){
    			$q = $this->db->row("SELECT * FROM `chat` WHERE `user` = '".intval($_SESSION['steamid'])."' ORDER BY `id` DESC LIMIT 1");
    			if($q->time+1 <= time()){
    				if($q->text != $this->checkAd($this->sql($msg))) {
    					$r = $this->db->query("INSERT INTO `chat` (`user`,`text`,`time`) VALUES ('".intval($_SESSION['steamid'])."', '".$this->sql($this->checkAd($msg))."', ".time().")");
    					return json_encode(array("success" => true,));
    				} else {
    					return json_encode(array("success" => false, "msg" => "flood"));
    				}
    			} else {
    				return json_encode(array("success" => false, "msg" => "flood"));
    			}
    		} else {
    			json_encode(array("success" => false, "msg" => "null_msg"));
    		}
    	} else {
    		return json_encode(array("success" => false, "msg" => "not_auth"));
    	}
    }

    enly1, 14 Июня 2017

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