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

    Всего: 5

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

    +148

    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
    #include <iostream.h>
    
    typedef short *(*bar2)(double);
    
    typedef char *(*bar3)();
    
    typedef long long int **(* bar5)();
    
    typedef bar5 (** bar4)(bar3);
    typedef bar4 (** bar1)(bar2);
    
    
    typedef long long int *(*(*(*(*(**bar0)(short *(*)(double ))))(char *(*)()))());
    
    
    long long int ** func5()
    {
    	static long long int  A = 42;
    	static long long int* B = &A;
    	return &B;
    }
    
    char* func3()
    {
    	return new char;
    }
    
    bar5 func4(bar3 A)
    {
    	return &func5;
    }
    
    short* fun2(double A)
    {
    	return new short;
    };
    
    bar4 fun1(bar2 A){
    	static void* p = &func4;
    	return (bar4)&p;
    }
    
    #pragma argsused
    int main(int argc, char* argv[])
    {
    	void* p = &fun1;
    
    	bar0 foo0 = (bar1)&p;
    	bar1 foo1 = (bar1)&p;
    
    	long long int ** pr1 = (*(*(*foo1)(&fun2))(&func3))();
    	long long int ** pr0 = (*(*(*foo0)(&fun2))(&func3))();
    
    	std::cout<<**pr1<<std::endl;
    	std::cout<<**pr0<<std::endl;
    	std::cin.get();
    
    	return 0;
    }

    разбирался с указателями на функции

    sanchousf, 25 Января 2012

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

    +134

    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
    99. 99
    int _Mbtowcx(wchar_t *pwc, const char *s, size_t nin, mbstate_t *pst, _Statab *pmbstate)
    	char state = (char)pst->_State;
    	unsigned char *su = (unsigned char *)s;
    	wchar_t wc = (wchar_t)pst->_Wchar;
    	static const mbstate_t initial = {0};
    
    	if (pmbstate->_Tab[0] == 0)	{	/* no table, convert from UTF8 */
    		if (s == 0)
    			{	/* set initial state */
    			*pst = initial;
    			return (0);
    			}
    
    		for (; ; ++su, --nin) {	/* consume an input byte */
    			if (nin == 0) {	/* report incomplete conversion */
    				pst->_Wchar = wc;
    				pst->_State = state;
    				return (-2);
    				}
    			else if (0 < state)	{	/* fold in a successor byte */
    				if ((*su & 0xc0) != 0x80) {	/* report invalid sequence */
    					errno = EILSEQ;
    					return (-1);
    					}
    				wc = (wchar_t)((wc << 6) | (*su & 0x3f));
    				--state;
    				}
    			else if ((*su & 0x80) == 0)
    				wc = *su;	/* consume a single byte */
    			else if ((*su & 0xe0) == 0xc0)	{	/* consume first of two bytes */
    				wc = (wchar_t)(*su & 0x1f);
    				state = 1;
    				}
    			else if ((*su & 0xf0) == 0xe0)	{	/* consume first of three bytes */
    				wc = (wchar_t)(*su & 0x0f);
    				state = 2;
    				}
    
    			else{	/* report invalid sequence */
    				errno = EILSEQ;
    				return (-1);
    				}
    			if (state == 0)	{	/* produce an output wchar */
    				if (pwc != 0)
    					*pwc = wc;
    				pst->_State = 0;
    				return (wc == 0 ? 0 : (const char *)++su - s);
    				}
    			}
    
    		}
    	else
    		{	/* run finite state machine */
    		int limit = 0;
    
    		if (s == 0)	{	/* set initial state */
    			*pst = initial;
    			return (pmbstate->_Tab[0][0] & _ST_STATE);
    			}
    
    		for (; ; )	{	/* perform a state transformation */
    			unsigned short code;
    			const unsigned short *stab;
    
    			if (nin == 0)
    				{	/* report incomplete conversion */
    				pst->_Wchar = wc;
    				pst->_State = state;
    				return (-2);
    				}
    			else if (_NSTATE <= state
    				|| (stab = pmbstate->_Tab[state]) == 0
    				|| (_NSTATE*UCHAR_MAX) <= ++limit
    				|| (code = stab[*su]) == 0)
    				{	/* report invalid sequence */
    				errno = EILSEQ;
    				return (-1);
    				}
    			state = (char)((code & _ST_STATE) >> _ST_STOFF);
    			if (code & _ST_FOLD)
    				wc = (wchar_t)(wc & ~UCHAR_MAX | code & _ST_CH);
    			if (code & _ST_ROTATE)
    				wc = (wchar_t)(wc << CHAR_BIT | UCHAR_MAX
    					& wc >> CHAR_BIT * (sizeof (wchar_t) - 1));
    			if (code & _ST_INPUT && *su != '\0')
    				++su, --nin, limit = 0;
    			if (code & _ST_OUTPUT)
    				{	/* produce an output wchar */
    				int nused = (const char *)su - s;
    
    				if (pwc)
    					*pwc = wc;
    				pst->_Wchar = wc;
    				pst->_State = state;
    				return (wc == 0 ? 0 : nused == 0 ? -3 : nused);
    				}
    			}
    		}
    	}

    Долго не мог понять почему не работает
    setlocale(...);
    _setmbcp(...);
    mbtowc(...);

    на C++ Builder. Пока не заглянул в исходники.

    sanchousf, 05 Апреля 2011

    Комментарии (17)
  4. C++ / Говнокод #4275

    +169

    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
    if(typeid(*Line1)==typeid(TLine)) ; else
    if(typeid(*Line2)==typeid(TLine)) {cLine=Line1; Line1=Line2; Line2=cLine;} else
    if(typeid(*Line1)==typeid(TRay)) ; else
    if(typeid(*Line2)==typeid(TRay)) {cLine=Line1; Line1=Line2; Line2=cLine;} else
    if(typeid(*Line1)==typeid(TLineSegment)) ; else
    if(typeid(*Line2)==typeid(TLineSegment)) {cLine=Line1; Line1=Line2; Line2=cLine;}
    
    if(typeid(*Line1)==typeid(TLine)) {
    	if(typeid(*Line2)==typeid(TLine))  return 1; else
    	if(typeid(*Line2)==typeid(TRay)) {
    		if(
    			(( ((TRay*)Line2)->X1<=((TRay*)Line2)->X2 && ((TRay*)Line2)->X1<=Point.x )  ||
    			 ( ((TRay*)Line2)->X1>=((TRay*)Line2)->X2 && ((TRay*)Line2)->X1>=Point.x )) &&
    			(( ((TRay*)Line2)->Y1<=((TRay*)Line2)->Y2 && ((TRay*)Line2)->Y1<=Point.y )  ||
    			 ( ((TRay*)Line2)->Y1>=((TRay*)Line2)->Y2 && ((TRay*)Line2)->Y1>=Point.y ))
    		  )
    			return 1;
    		else
    			return -1;
    	} else
    	if(typeid(*Line2)==typeid(TLineSegment)) {
    		if(
    			(( ((TLineSegment*)Line2)->X1<=Point.x && Point.x<=((TLineSegment*)Line2)->X2 )||( ((TLineSegment*)Line2)->X2<=Point.x && Point.x<=((TLineSegment*)Line2)->X1 )) &&
    			(( ((TLineSegment*)Line2)->Y1<=Point.y && Point.y<=((TLineSegment*)Line2)->Y2 )||( ((TLineSegment*)Line2)->Y2<=Point.y && Point.y<=((TLineSegment*)Line2)->Y1 ))
    		  )
    			return 1;
    		  else
    			return -1;
    	}
    } else
    if(typeid(*Line1)==typeid(TRay)) {
    	if(typeid(*Line2)==typeid(TRay)) {
    		if(
    			((( ((TRay*)Line1)->X1<=((TRay*)Line1)->X2 && ((TRay*)Line1)->X1<=Point.x )  ||
    			  ( ((TRay*)Line1)->X1>=((TRay*)Line1)->X2 && ((TRay*)Line1)->X1>=Point.x )) &&
    			 (( ((TRay*)Line1)->Y1<=((TRay*)Line1)->Y2 && ((TRay*)Line1)->Y1<=Point.y )  ||
    			  ( ((TRay*)Line1)->Y1>=((TRay*)Line1)->Y2 && ((TRay*)Line1)->Y1>=Point.y )))
    			&&
    			((( ((TRay*)Line2)->X1<=((TRay*)Line2)->X2 && ((TRay*)Line2)->X1<=Point.x )  ||
    			  ( ((TRay*)Line2)->X1>=((TRay*)Line2)->X2 && ((TRay*)Line2)->X1>=Point.x )) &&
    			 (( ((TRay*)Line2)->Y1<=((TRay*)Line2)->Y2 && ((TRay*)Line2)->Y1<=Point.y )  ||
    			  ( ((TRay*)Line2)->Y1>=((TRay*)Line2)->Y2 && ((TRay*)Line2)->Y1>=Point.y )))
    		  )
    			return 1;
    		else
    			return -1;
    	} else
    	if(typeid(*Line2)==typeid(TLineSegment)) {
    		if(
    			((( ((TRay*)Line1)->X1<=((TRay*)Line1)->X2 && ((TRay*)Line1)->X1<=Point.x )  ||
    			  ( ((TRay*)Line1)->X1>=((TRay*)Line1)->X2 && ((TRay*)Line1)->X1>=Point.x )) &&
    			 (( ((TRay*)Line1)->Y1<=((TRay*)Line1)->Y2 && ((TRay*)Line1)->Y1<=Point.y )  ||
    			  ( ((TRay*)Line1)->Y1>=((TRay*)Line1)->Y2 && ((TRay*)Line1)->Y1>=Point.y )))
    			&&
    			((( ((TLineSegment*)Line2)->X1<=Point.x && Point.x<=((TLineSegment*)Line2)->X2 )||( ((TLineSegment*)Line2)->X2<=Point.x && Point.x<=((TLineSegment*)Line2)->X1 )) &&
    			((  ((TLineSegment*)Line2)->Y1<=Point.y && Point.y<=((TLineSegment*)Line2)->Y2 )||( ((TLineSegment*)Line2)->Y2<=Point.y && Point.y<=((TLineSegment*)Line2)->Y1 )))
    		  )
    			return 1;
    		else
    			return -1;
    	}
    	return 1;
    } else
    if(typeid(*Line1)==typeid(TLineSegment)) {
    	if(
    		((( ((TLineSegment*)Line1)->X1<=Point.x && Point.x<=((TLineSegment*)Line1)->X2 )||( ((TLineSegment*)Line1)->X2<=Point.x && Point.x<=((TLineSegment*)Line1)->X1 )) &&
    		((  ((TLineSegment*)Line1)->Y1<=Point.y && Point.y<=((TLineSegment*)Line1)->Y2 )||( ((TLineSegment*)Line1)->Y2<=Point.y && Point.y<=((TLineSegment*)Line1)->Y1 )))
    		&&
    		((( ((TLineSegment*)Line2)->X1<=Point.x && Point.x<=((TLineSegment*)Line2)->X2 )||( ((TLineSegment*)Line2)->X2<=Point.x && Point.x<=((TLineSegment*)Line2)->X1 )) &&
    		((  ((TLineSegment*)Line2)->Y1<=Point.y && Point.y<=((TLineSegment*)Line2)->Y2 )||( ((TLineSegment*)Line2)->Y2<=Point.y && Point.y<=((TLineSegment*)Line2)->Y1 )))
    	  )
    		return 1;
    	else
    		return -1;
    }

    Имеются классы:
    class TLine; // Линия
    class TRay: public TLine; // Луч
    class TLineSegment: public TRay; // Отрезок
    Функция записывает в Point точку пересечения прямых и возвращает 0 если прямые параллельны, -1 если пересекаются продолжения отрезков и 1 если пересекаются отрезки.
    Выше представлен кусок кода где проводится проверка, принадлежит точка пересечения отрезкам или их продолжениям.

    sanchousf, 17 Сентября 2010

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

    +138

    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
    static const char*const nullp,From_[]=FROM,exflags[]=RECFLAGS,
     drcfile[]="Rcfile:",pmusage[]=PM_USAGE,*etcrc=ETCRC,
     misrecpt[]="Missing recipient\n",extrns[]="Extraneous ",ignrd[]=" ignored\n",
     pardir[]=chPARDIR,curdir[]={chCURDIR,'\0'},
     insufprivs[]="Insufficient privileges\n",
     attemptst[]="Attempt to fake stamp by";
    char*buf,*buf2,*loclock,*tolock;
    const char shell[]="SHELL",lockfile[]="LOCKFILE",newline[]="\n",binsh[]=BinSh,
     unexpeof[]="Unexpected EOL\n",*const*gargv,*const*restargv= &nullp,*sgetcp,
     pmrc[]=PROCMAILRC,*rcfile=pmrc,dirsep[]=DIRSEP,devnull[]=DevNull,
     lgname[]="LOGNAME",executing[]="Executing",oquote[]=" \"",cquote[]="\"\n",
     procmailn[]="procmail",whilstwfor[]=" whilst waiting for ",home[]="HOME",
     host[]="HOST",*defdeflock,*argv0="",errwwriting[]="Error while writing to",
     slogstr[]="%s \"%s\"",conflicting[]="Conflicting ",orgmail[]="ORGMAIL",
     exceededlb[]="Exceeded LINEBUF\n",pathtoolong[]=" path too long";
    char*Stdout;
    int retval=EX_CANTCREAT,retvl2=EXIT_SUCCESS,sh,pwait,lcking,rcstate,rc= -1,
     ignwerr,lexitcode=EXIT_SUCCESS,asgnlastf,accspooldir,crestarg,skiprc,
     savstdout,berkeley,mailfilter,erestrict;
    size_t linebuf=mx(DEFlinebuf+XTRAlinebuf,1024/*STRLEN(systm_mbox)<<1*/);
    volatile int nextexit;			       /* if termination is imminent */
    pid_t thepid;
    long filled,lastscore;	       /* the length of the mail, and the last score */
    char*themail,*thebody;			    /* the head and body of the mail */
    uid_t uid;
    gid_t gid,sgid;

    Источник: http://opensource.apple.com/source/procmail/procmail-1.2/procmail/src/procmail.c

    sanchousf, 31 Августа 2010

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

    +164

    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
    class Cmd
    {
    private:  /* ... */
    protected: /* ... */
    public:
    	virtual void Assign(Cmd *Source) {}
    	/* ... */
    };
    //---------------------------------------------------------------------------
    class UARTCmd: public Cmd
    {
    private: /* ... */
    protected:
    	byte FCode;
    	unsigned short FCRCbytes;
    	int FLenData;
    	byte FData[256];
    	unsigned short FInit_CRC;
    	unsigned short FPoly_CRC;
    
    	TypeCommand TypeCmd;
    public:
    	virtual void Assign(Cmd *Source) { /* .1. */ }
    	/* ... */
    };
    //---------------------------------------------------------------------------
    class TRANSITCmd: public Cmd
    {
    private: /* ... */
    protected:
    	byte FCode;
    	unsigned short FCRCbytes;
    	int FLenData;
    	byte FData[256];
    	unsigned short FInit_CRC;
    	unsigned short FPoly_CRC;
    
    	byte FID;
    
    	unsigned short FNumb;
    public:
    	virtual void Assign(Cmd *Source) { /* .2. */ /* .3. */ }
    	/* ... */
    };
    //---------------------------------------------------------------------------
    class ASKCmd: public Cmd
    {
    private: /* ... */
    protected:
    	byte FCode;
    	unsigned short FCRCbytes;
    	int FLenData;
    	byte FData[256];
    	unsigned short FInit_CRC;
    	unsigned short FPoly_CRC;
    
    	byte FID;
    
    	byte FidFrom;
    	byte FTimeR;
    	unsigned short FSID;
    public:
    	virtual void Assign(Cmd *Source) { /* .2. */ /* .4. */ }
    	/* ... */
    };
    //---------------------------------------------------------------------------
    class RESPCmd: public Cmd
    {
    private: /* ... */
    protected:
    	byte FCode;
    	unsigned short FCRCbytes;
    	int FLenData;
    	byte FData[256];
    	unsigned short FInit_CRC;
    	unsigned short FPoly_CRC;
    
    	byte FID;
    
    	byte FidFrom;
    	byte FTimeR;
    	unsigned short FSID;
    
    	byte FidResp;
    	unsigned short FCRCResp;
    public:
    	virtual void Assign(Cmd *Source) { /* .2. */ /* .4. */ /* .5. */ }
    	/* ... */
    };

    Сие чудо я должен реализовывать! Так сказать, привести в порядок код.

    P.S. Первоначальный вариант выглядит в разы лучше.
    P.P.S. /* .1. */ - обозначает часть кода

    sanchousf, 30 Августа 2010

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