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

    Всего: 3

  2. C++ / Говнокод #13150

    +10

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public ref class Form1 : public System::Windows::Forms::Form
    {
    private: char * StrToCharArray ( System::String ^ inStr )
    {
        pin_ptr<const wchar_t> wch_basename = PtrToStringChars( inStr );
        size_t convertedChars = 0; size_t  sizeInBytes = ((inStr->Length + 1) * 2);
        char * ch_basename = (char *)malloc(sizeInBytes);
        wcstombs_s(&convertedChars, ch_basename, sizeInBytes, wch_basename, sizeInBytes);
     return ch_basename;
    }
    }

    C++/CLI

    sokol, 11 Июня 2013

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

    +103

    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
    void str2ip_s_Before( unsigned char* ptrIP, unsigned short* ptrPort, const wchar_t* src, size_t count )
    {
        int i;
        if( !ptrIP )
            return;
    
        while( src && count && !iswdigit( *src ) )//skip separators and spaces
            ++src, --count;
    
        for( i = 0; i < 4 && count; ++i )//IP address
        {
            ptrIP[ i ] = ( unsigned char )_wtoi( src );
    
            while( src && count && iswdigit( *src ) )//skip current number
                ++src, --count;
    
            while( src && count && !iswdigit( *src ) )//skip separators and spaces
                ++src, --count;
        }
    
        if( ptrPort && src && count )
            *ptrPort = ( unsigned short )_wtoi( src );
    }
    
    int str2ip_sAfter( unsigned char* ptrIP, unsigned short* ptrPort, const wchar_t* src, size_t count )
    {
        int i, iRadix;
        wchar_t* endptr;
    
        if( !ptrIP || !src || 0 == count )
            return 0;
    
        for( i = 0; i < 4; ++i )
            ptrIP[ i ] = 0;
        if( ptrPort )
            *ptrPort = 0;
    
        while( 0 != count && !iswdigit( *src ) ) //skip separators and spaces
            ++src, --count;
    
        for( i = 0; i < 4 && 0 != count; ++i ) //IP address
        {
            if( count > 1 && src[ 0 ] == L'0' )
            {
                if( src[ 1 ] != L'x' && src[ 1 ] != L'X' )
                    iRadix = 8;
                else
                    iRadix = 16;
            }
            else
                iRadix = 10;
    
            ptrIP[ i ] = ( unsigned char )wcstol( src, &endptr, iRadix );
            if( src == endptr )
                return 0;
            count -= endptr - src;
            src = endptr;
    
            while( 0 != count && iswspace( *src ) ) //skip spaces
                ++src, --count;
    
            if( i < 3 )
            {
                if( L'.' == *src ) //skip point
                    ++src, --count;
                else
                    return 0;
            }
    
            while( 0 != count && iswspace( *src ) ) //skip spaces
                ++src, --count;
        }
    
        if( i < 4 )
            return 0;
    
        if( ptrPort )
        {
            if( 0 == count || L':' != *src ) //skip point
                return 0;
            ++src, --count;
    
            while( 0 != count && iswspace( *src ) ) //skip spaces
                ++src, --count;
    
            *ptrPort = ( unsigned short )wcstol( src, &endptr, 10 );
            if( src == endptr )
                return 0;
            else
                return 1;
        }
        else
            return 1;
    }

    Пуресишник зарефакторил

    sokol, 31 Августа 2012

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

    +123

    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
    int closeestsockptr( SOCKET* pSocket )
    {
    	char chBuf[ 100 ];
    	fd_set rdevents, exevents;
    	struct timeval tv;
    	int iRetVal = 1;
    	int optlen;
    	SOCKET s = INVALID_SOCKET;
    	BOOL bLinger;
    	LINGER lng;
    	if( NULL == pSocket || INVALID_SOCKET == *pSocket )
    		return SOCKET_ERROR;
    	s = *pSocket;
    	optlen = sizeof( bLinger );
    	iRetVal = getsockopt( s, SOL_SOCKET, SO_DONTLINGER, ( char* )&bLinger, &optlen );
    	if( 0 == iRetVal && TRUE == bLinger ) //linger is off
    	{
    		lng.l_onoff = 1; //set linger on
    		lng.l_linger = 1; //set linger timeout to 1 second
    		iRetVal = setsockopt( s, SOL_SOCKET, SO_LINGER, ( char* )&lng, sizeof( lng ) );
    		if( 0 == iRetVal )
    		{
    			if( 0 == shutdown( s, SD_SEND ) )
    			{
    				tv.tv_sec = 3; //seconds
    				tv.tv_usec = 0; //microseconds
    				while( 1 )
    				{
    					FD_ZERO( &rdevents );
    					FD_ZERO( &exevents );
    					addsock2fd( &rdevents, NULL, &exevents, s ); //FD_SET( s, &rdevents ), FD_SET( s, &exevents );
    					iRetVal = select( 1, &rdevents, NULL, &exevents, &tv );
    					if( SOCKET_ERROR != iRetVal && 0 != iRetVal && FD_ISSET ( s, &rdevents ) && !FD_ISSET ( s, &exevents ) )
    					{
    						iRetVal = recv( s, chBuf, sizeof( chBuf ) / sizeof( *chBuf ), 0 );
    						if( iRetVal > 0 ) //Some data received
    							continue;
    						if( 0 == iRetVal ) //Receive FD_CLOSE
    							break;
    						else //SOCKET_ERROR returned
    							break;
    					}
    					else if( 0 == iRetVal ) //exceeded the timeout
    					{
    						WSASetLastError( WSAETIMEDOUT );
    						break;
    					}
    					else //SOCKET_ERROR returned
    						break;
    				}
    			}
    		}
    	}
    
    	if( NULL == pSocket || INVALID_SOCKET == *pSocket )
    		return SOCKET_ERROR;
    	iRetVal = closesocket( *pSocket );
    	*pSocket = INVALID_SOCKET;
    	return iRetVal;
    }

    Пуресишник наваял

    sokol, 29 Августа 2012

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