1. C++ / Говнокод #23144

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    void DrawLine(Vec2Si32 a, Vec2Si32 b, Rgba color_a, Rgba color_b) { // https://pastebin.com/p26FvZdd
        Vec2Si32 ab = b - a;
        Vec2Si32 abs_ab(std::abs(ab.x), std::abs(ab.y));
        if (abs_ab.x >= abs_ab.y) {
            if (a.x > b.x) {
                DrawLine(b, a, color_b, color_a);
            } else {
                Sprite back = GetEngine()->GetBackbuffer();
                Vec2Si32 back_size = back.Size();
                if (ab.x == 0) {
                    if (a.x >= 0 && a.x < back_size.x &&
                            a.y >= 0 && a.y < back_size.y) {
                        back.RgbaData()[a.x + a.y * back.StridePixels()] = color_a;
                    }
                    return;
                }
                Si32 x1 = std::max(0, a.x);
                Si32 x2 = std::min(back_size.x - 1, b.x);
                Si32 y1 = a.y + ab.y * (x1 - a.x) / ab.x;
                Si32 y2 = a.y + ab.y * (x2 - a.x) / ab.x;
                if (y1 < 0) {
                    if (y2 < 0) {
                        return;
                    }
                    // lower left -> upper right
                    y1 = 0;
                    x1 = a.x + ab.x * (y1 - a.y) / ab.y;
                    x1 = std::max(0, x1);
                } else if (y1 >= back_size.y) {
                    if (y2 >= back_size.y) {
                        return;
                    }
                    // upper left -> lower right
                    y1 = back_size.y - 1;
                    x1 = a.x + ab.x * (y1 - a.y) / ab.y;
                    x1 = std::max(0, x1);
                }
                if (y2 < 0) {
                    // upper left -> lower right
                    y2 = 0;
                    x2 = a.x + ab.x * (y2 - a.y) / ab.y;
                    x2 = std::min(back_size.x - 1, x2);
                } else if (y2 >= back_size.y) {
                    // lower left -> upper right
                    y2 = back_size.y - 1;
                    x2 = a.x + ab.x * (y2 - a.y) / ab.y;
                    x2 = std::min(back_size.x - 1, x2);
                }
                Vec4Si32 rgba_a(static_cast<Si32>(color_a.r),static_cast<Si32>(color_a.g),static_cast<Si32>(color_a.b),static_cast<Si32>(color_a.a));
                Vec4Si32 rgba_b(static_cast<Si32>(color_b.r),static_cast<Si32>(color_b.g),static_cast<Si32>(color_b.b),static_cast<Si32>(color_b.a));
                Vec4Si32 rgba_ab = rgba_b - rgba_a;
                Vec4Si32 rgba_1 = rgba_a + rgba_ab * (x1 - a.x) / ab.x;
                Vec4Si32 rgba_2 = rgba_a + rgba_ab * (x2 - a.x) / ab.x;
                Vec4Si32 rgba_12 = rgba_2 - rgba_1;
                if (x2 <= x1) {
                    if (x2 == x1) {
                        Rgba color(rgba_1.x, rgba_1.y, rgba_1.z, rgba_1.w);
                        back.RgbaData()[x1 + y1 * back.StridePixels()] = color;
                    }
                    return;
                }
                Vec4Si32 rgba_16 = rgba_1 * 65536;
                Vec4Si32 rgba_12_16 = rgba_12 * 65536;
                Vec4Si32 rgba_12_16_step = rgba_12_16 / (x2 - x1);
                Si32 y_16 = y1 * 65536;
                Si32 y12_16_step = ((y2 - y1) * 65536) / (x2 - x1);
                Si32 stride = back.StridePixels();
                for (Si32 x = x1; x <= x2; ++x) {
                    Rgba color(rgba_16.x >> 16,rgba_16.y >> 16,rgba_16.z >> 16,rgba_16.w >> 16);
                    back.RgbaData()[x + (y_16 >> 16) * stride] = color;
                    rgba_16 += rgba_12_16_step;
                    y_16 += y12_16_step;
                }
            }
        } else { // тут почти тоже самое
            if (a.y > b.y) {
                DrawLine(b, a, color_b, color_a);
            } else {
                Sprite back = GetEngine()->GetBackbuffer();
                Vec2Si32 back_size = back.Size();
                if (ab.y == 0) {
                    if (a.y >= 0 && a.y < back_size.y && a.x >= 0 && a.x < back_size.x) {
                        back.RgbaData()[a.x + a.y * back.StridePixels()] = color_a;
                    }
                    return;
                }
                Si32 y1 = std::max(0, a.y);
                Si32 y2 = std::min(back_size.y - 1, b.y);
                Si32 x1 = a.x + ab.x * (y1 - a.y) / ab.y;
                Si32 x2 = a.x + ab.x * (y2 - a.y) / ab.y;
                if (x1 < 0) {
                    if (x2 < 0) {
                        return;
                    }
                    // lower left -> upper right
                    x1 = 0;
                    y1 = a.y + ab.y * (x1 - a.x) / ab.x;
                    y1 = std::max(0, y1);
                } else if (x1 >= back_size.x) {
                    if (x2 >= back_size.x) {

    Взято отсюда https://github.com/FrostyMorning/arctic/blob/master/engine/easy.cpp
    https://pastebin.com/p26FvZdd

    cin, 22 Июня 2017

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

    +2

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

    ldv_a, 16 Июня 2017

    Комментарии (0)
  9. 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)
  10. 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)