1. Список говнокодов пользователя mittorn

    Всего: 36

  2. bash / Говнокод #25122

    −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
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    names="com.termux io.twaik.lorie rubberbigpepper.Orientator"
    if test ! -e /realproc/cmdline
    then
    echo Mounting realproc
    mount -o remount,rw none /
    mkdir /realproc
    mount -t proc none /realproc
    fi
    
    tail -f /dev/null|am monitor| while read line
    do
    echo "$line"
    for n in $names
    do
    for p in `pidof $n`
    do
    if test -e /proc/$p/oom_adj
    then
    echo Masking pid $p
    mount -t tmpfs -o size=4k none /proc/$p/
    for f in /realproc/$p/*
    do ln -s $f /proc/$p
    done
    rm /proc/$p/oom_*
    fi
    echo Setting oom adj for $n $p, was $(cat /realproc/$p/oom_adj)
    echo -17 > /realproc/$p/oom_adj
    done
    done
    done

    достал oom killer.

    Где тут shell в языках?

    mittorn, 27 Ноября 2018

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

    −2

    1. 1
    echo $(printf '1\xff0.0.0.0:0\0\\gamedir\\valve' |nc -u ms.xash.su 27010 -w 1 | od -j6 -t x1 -An -w6 |sed -s 's/\ /\ 0x/g'|while read line; do printf '%d.%d.%d.%d' $(echo $line|cut -d ' ' -f1-4) ; echo \ $(( $(printf %d $(echo $line|cut -d ' ' -f5))*256 + $(printf %d $(echo $line|cut -d ' ' -f6)) )); done| while read line1; do printf \\xff\\xff\\xff\\xffinfo\ 48|nc -w 1 -u $line1 |sed -e s/\\\\/\\\ /g -e "s/\xff\xff\xff\xffinfo/_br_$line1/g" & done;sleep 2s;echo)|sed -e s/_br_/\\n/g

    Работаем с бинарными протоколами однострочно

    mittorn, 17 Мая 2018

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

    +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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    /* 
    ================== 
    CL_ScreenshotGetName
    ================== 
    */  
    void CL_ScreenshotGetName( int lastnum, char *filename )
    {
    	int	a, b, c, d;
    
    	if( lastnum < 0 || lastnum > 9999 )
    	{
    		// bound
    		Q_sprintf( filename, "scrshots/%s/!error.bmp", clgame.mapname );
    		return;
    	}
    
    	a = lastnum / 1000;
    	lastnum -= a * 1000;
    	b = lastnum / 100;
    	lastnum -= b * 100;
    	c = lastnum / 10;
    	lastnum -= c * 10;
    	d = lastnum;
    
    	Q_sprintf( filename, "scrshots/%s_shot%i%i%i%i.bmp", clgame.mapname, a, b, c, d );
    }

    один вопрос: НАХУЯ???

    mittorn, 18 Июля 2017

    Комментарии (1)
  5. C++ / Говнокод #22870

    −12

    1. 1
    #if defined(SOCI_MYSQL_FOUND) && SOCI_MYSQL_FOUND != 0

    t-odbo/os-odbo.cpp:890:51: error: operator
    '&&' has no right operand

    mittorn, 29 Апреля 2017

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

    −20

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
    err = "sshttp::init::setrlimit:";
    err = strerror(errno);
    return -1;
    }

    https://github.com/stealth/sshttp/blob/master/sshttp.cc
    Хоть я и нашёл эту ошибку, завести его в lxc так и не удалось. Первое соединение зависает, а остальные выдают connection reset by peer
    Ищутся другие способы выжить с одним ssh портом

    mittorn, 03 Февраля 2017

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

    −22

    1. 1
    2. 2
    3. 3
    4. 4
    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
    public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

    https://github.com/skypeopensource/skypeopensource2/blob/master/EpycsMessenger2/EpycsMessenger2/Form1.cs
    Я шорпов не знаю, но мне кажется, что что-то тут не так

    mittorn, 04 Сентября 2016

    Комментарии (113)
  8. Си / Говнокод #20413

    −49

    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
    void CL_SendDisconnectMessage( void )
    {
    	sizebuf_t	buf;
    	byte	data[32];
    
    	if( cls.state == ca_disconnected ) return;
    
    	BF_Init( &buf, "LastMessage", data, sizeof( data ));
    	BF_WriteByte( &buf, clc_stringcmd );
    	BF_WriteString( &buf, "disconnect" );
    
    	if( !cls.netchan.remote_address.type )
    		cls.netchan.remote_address.type = NA_LOOPBACK;
    
    	// make sure message will be delivered
    	Netchan_Transmit( &cls.netchan, BF_GetNumBytesWritten( &buf ), BF_GetData( &buf ));
    	Netchan_Transmit( &cls.netchan, BF_GetNumBytesWritten( &buf ), BF_GetData( &buf ));
    	Netchan_Transmit( &cls.netchan, BF_GetNumBytesWritten( &buf ), BF_GetData( &buf ));
    }

    Ну чтоб наверняка.

    mittorn, 22 Июля 2016

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

    −51

    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
    96. 96
    97. 97
    98. 98
    xash_force_inline size_t Q_strncat( char *dst, const char *src, size_t size )
    {
    	register const char	*pchr;
    	register const unsigned int *plongword;
    	register unsigned int *pdst;
    	register unsigned int len;
    
    	const unsigned int himagic = 0x80808080, lomagic = 0x01010101;
    
    	if( !dst || !src || !size )
    		return 0;
    
    	len = Q_strlen( dst );
    	dst += len;
    		
    
    	if( ( unsigned long int )src & ( sizeof( int ) - 1) != ( unsigned long int )dst & ( sizeof( int ) - 1) )
    		return len + Q_strncpy_unaligned( dst, src, size - len );
    
    	// first, copy all unaligned bytes
    	for( pchr = src; ( ( unsigned long int )pchr & ( sizeof( int ) - 1) ) != 0; pchr++, len++, dst++ )
    	{
    		*dst = *pchr;
    		if( len >= size )
    		{
    			*dst = '\0';
    			return len;
    		}
    		
    		if( *pchr == '\0' )
    			return len;
    	}
    
    	plongword = ( const unsigned int * ) pchr;
    	pdst = ( unsigned int * ) dst;
    
    	// plongword is aligned now, copy by 4 bytes
    	while( true )
    	{
    		register unsigned int longword = *plongword++;
    
    		// if magic check failed
    		if( ( ( longword - lomagic ) & himagic ) != 0 || (size - len < 4) )
    		{
    			const char *pchar = ( const char * )( plongword - 1 );
    			char *pchdst = ( char * )( pdst );
    			int i;
    
    
    			for( i = 0; i < 4; i++ )
    			{
    				pchdst[i] = pchar[i];
    
    				if( len + i >= size )
    				{
    					pchdst[i] = '\0';
    					return len + i;
    				}
    				if( pchar[i] == 0 )
    					return len + i;
    			}
    		}
    
    		len += sizeof( longword );
    		*pdst++ = longword;
    	}
    	return 0;
    }
    
    /*
     * sanity checker
    xash_force_inline size_t Q_strncat( char *dst, const char *src, size_t size )
    {
    	char buf1[100000], buf2[100000], r1, r2;
    	if( !dst || !src || !size )
    		return 0;
    	if( size > 99999 )
    		size = 99999;
    	strncpy( buf1, dst, size );
    	strncpy( buf2, dst, size );
    	buf1[99999] = buf2[99999] = 0;
    
    	r1 = Q_strncat_( buf1, src, size );
    	r2 = Q_strncat2( buf2, src, size );
    	if( r1 != r2 )
    		printf("DIFFERENT RESULT %d %d %d %d %s\n%s\n", r1, r2, aligned, counter, buf1, src);
    	if( strcmp( buf1, buf2 ) )
    	{
    		printf("DIFFERENT DATA %s %d %d %d %4s\n", src, size, aligned, counter, last);
    		printf("1: %s\n", buf1);
    		printf("2: %s\n", buf2);
    		
    	}
    	//strncpy( dst, buf1, size );
    	return Q_strncat2(dst, src, size);
    	
    }
    */

    Оптимизация удалась, однако при виде этого кода становится не по себе. Что можно с этим сделать?

    mittorn, 27 Мая 2016

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

    −46

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int main()
    {
    setuid(0);
    return system("echo mem > /sys/power/state");
    }

    А ведь году в 2012 это ещё решалось через consolekit

    mittorn, 29 Апреля 2016

    Комментарии (8)
  11. Си / Говнокод #19873

    −48

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    typedef float		vec_t;
    ...
    typedef vec_t		matrix3x4[3][4];
    ...
    void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 );
    ...
    static matrix3x4		g_bonestransform[MAXSTUDIOBONES];
    static matrix3x4		g_rotationmatrix;
    ...
        matrix3x4		bonematrix;
    ...
        Matrix3x4_ConcatTransforms( g_bonestransform[i], g_rotationmatrix, bonematrix );

    Поясните, что не так?

    Ругань gcc такова:
    client/gl_studio.c:1076:5: warning: passing argument 2 of ‘Matrix3x4_ConcatTransforms’ from incompatible pointer type [enabled by default]
    common/mathlib.h:144:6: note: expected ‘const vec_t (*)[4]’ but argument is of type ‘vec_t (*)[4]’
    client/gl_studio.c:1076:5: warning: passing argument 3 of ‘Matrix3x4_ConcatTransforms’ from incompatible pointer type [enabled by default]
    common/mathlib.h:144:6: note: expected ‘const vec_t (*)[4]’ but argument is of type ‘vec_t (*)[4]’

    Ведь в функцию, принимающую const char* можно передавать char*? Что же тогда с матрицами то не так?

    mittorn, 24 Апреля 2016

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