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

    +156

    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 (licenseImageAvailable) {
        QPoint p1, p2, p3;
        p1.setX (top->getUIntSeq ("X1",licenseImageAvailable));
        p1.setY (top->getUIntSeq ("Y1",licenseImageAvailable));
        p2.setX (top->getUIntSeq ("X2",licenseImageAvailable));
        p2.setY (top->getUIntSeq ("Y2",licenseImageAvailable));
        p3.setX (top->getUIntSeq ("X3",licenseImageAvailable));
        p3.setY (top->getUIntSeq ("Y3",licenseImageAvailable));
    
        if (licenseImageAvailable)
          seq = seq && imageElement->getNeedJPEG (targetSize.width (),
                                                  targetSize.height (), &targetImg, top, &licenseImage, p1, p2, p3);
        else
          seq = seq && imageElement->getNeedJPEG (targetSize.width (), targetSize.height (), &targetImg, top);
      } else {
    
        seq = seq && imageElement->getNeedJPEG (targetSize.width (), targetSize.height (), &targetImg, top);
      }

    panter_dsd, 04 Апреля 2011

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

    +146

    1. 1
    this++;

    Думаю, так нельзя в члене класса, но выглядит все равно забавно.

    Говногость, 04 Апреля 2011

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

    +174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    const char * strtime(const time_t * t){
    	tm tt;
    	const int dt_len = 60;
    	char str_dt[dt_len];
    	localtime_r(t, &tt);
    	strftime(str_dt, dt_len, "%d.%m.%Y %H:%M:%S", &tt);
    	std::string str(str_dt);
    	return str.c_str();
    }

    Код, как ни странно, работал несколько лет, пока проект не трогали и байты не сместились. Неудивительно, что код вместо времени стал возвращать имя функции, из которого вызывался.

    Deacon, 04 Апреля 2011

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

    +168

    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
    #define TPLM Tuple(TPLMOVE) + 
    #define TPLC Tuple(TPLCOPY) + 
    #define TPL Tuple() + 
    //#define GTPL Tuple() +
    #define TPLERROR(t) { memcpy(0, 0, 1); }
    
    #define TPLMOVE    1 // copy to tuple, memset 0 original. = destruct dest, copy to dest.
    #define TPLCOPY    2 // copy constructor = destruct dest, copy to dest
    #define TPLGET    3 // destruct all values :)
    
    #include <memory.h>
    #include <math.h>
    #include <stdio.h>
    #include <typeinfo>
    #include <string.h>
    
    #define max(a, b) (((a) > (b)) ? (a) : (b))
    #define min(a, b) (((a) < (b)) ? (a) : (b))
    
    unsigned int mcrc(char* name, unsigned int sz){
        unsigned int ret=0; if(!sz) sz=(unsigned int)strlen(name);
        char*t=name+sz; int p=0;
        while(name<t){
            *(((char*)&ret)+p)+=*name; p++;
            if(p>=4) p=0; name++;
        }
    return ret;
    }
    
    struct Tupled{ unsigned int sz, type; void *v; char data[0]; };
    
    class Tuple{
        int count, set, dusz, dasz;
        unsigned char *data;
        int type; int adel; 
    
    public:
        Tuple(){ count=0; set=0; type=0; dusz=0; dasz=0; data=0; adel=0; }
        Tuple(int t){ type=t; }
    
        ~Tuple(){ if(count!=set) TPLERROR("~Tuple"); delete data; }
    
        Tuple(Tuple &t){
            count=t.count; set=t.set; dusz=t.dusz; dasz=t.dasz; data=t.data;
            t.count=0; t.set=0; t.data=0; adel=1;
        }
    
        template <class T>
        Tuple& operator+(T &t){ if(!adel) Add(&t, sizeof(t), t); else Del(&t, sizeof(t), t); return *this; }
        template <class T>
        Tuple& operator-(T &t){ if(!adel) Add(&t, sizeof(t), t); else Del(&t, sizeof(t), t); return *this; }
    
    /* Операторы '*', '/', ',', '>', '<' код идентичен */
    
        template <class T>
        void Add(void *v, int s, T &t){
            if(dasz-dusz<s+4+(int)sizeof(void*)){
                unsigned char *ldata=data;
                data=new unsigned char[dasz+max(128, s+4)];
                memcpy(data, ldata, dasz);
                dasz+=max(128, s);                    
                delete [] ldata;
            }
            Tupled &d=*(Tupled*)(data+dusz);
            d.sz=s;
            memcpy(&d.v, v, sizeof(void*));
            if(type==TPLCOPY){ *(T*)d.data=t; } else memcpy(d.data, v, s);
            if(type==TPLMOVE) t.~T();
    
            d.type=mcrc((char*)typeid(t).name(), 0);
            dusz+=sizeof(Tupled)+s; count++;
        }
    
        template <class T>
        void Del(void *v, int s, T &t){
            if(set>=count){ TPLERROR("Tuple::Set"); return ; }
            unsigned char *p=GetData(set);
            if(!p){ TPLERROR("Tuple::NoData"); return ; }
    
            Tupled &d=*(Tupled*)p;
            unsigned int tp=mcrc((char*)typeid(t).name(), 0);
            if(tp!=d.type){ TPLERROR("Tuple::TYPE"); return ;}
    
            t.~T();
            if(d.sz!=s){ TPLERROR("Tuple::SIZE"); return ;}
            memcpy(v, d.data, d.sz);
            
            set++;
        }
    
        unsigned char* GetData(int c){
            if(c>=count) return 0;
            unsigned char *p=data;
            for(int i=0; i<c; i++){
                p+=sizeof(Tupled)+*(int*)p;
            }
            return p;
        }
    };

    Очередной самобытный велосипед от микеля.

    http://rsdn.ru/forum/src/4218954.aspx

    cutwater, 02 Апреля 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    HMODULE nt=LoadLibrary("Ntdll.dll");
    PROCESS_BASIC_INFORMATION pbi={0};
    ZWQUERYINFORMATIONPROCESS _ZwQueryInformationProcess;
    _ZwQueryInformationProcess = (ZWQUERYINFORMATIONPROCESS)GetProcAddress(nt, "ZwQueryInformationProcess");
    DWORD rlg;
    SetLastError(0);
    _ZwQueryInformationProcess(divine,0,&pbi,sizeof(pbi),&rlg);
    printf("%d",GetLastError());

    источник: http://www.wasm.ru/forum/viewtopic.php?pid=426270#p426270

    ReL, 31 Марта 2011

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

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    QString SomeClass::newzipname (const QString serial) {
      QDateTime dt=QDateTime::currentDateTime();
      return serial
        +QString("%1%2%3%4%5%6")
        .arg (QString::number (dt.date().year()-2000), 2, '0')
        .arg (QString::number (dt.date().month()), 2, '0')
        .arg (QString::number (dt.date().day()), 2, '0')
        .arg (QString::number (dt.time().hour()), 2, '0')
        .arg (QString::number (dt.time().minute()), 2, '0')
        .arg (QString::number (dt.time().second()), 2, '0')
        +".zip";
    }

    panter_dsd, 31 Марта 2011

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

    +160

    1. 1
    2. 2
    3. 3
    private:
    private:
    	friend class boost::iterator_core_access;

    Никому не покажу своего друга-буста

    ClearHerdsman, 31 Марта 2011

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

    +159

    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
    enum EPlayerStat { ... };
    typedef std::pair<EPlayerStat, int> StatDelta;
    ...
    
    void GameClassT::showTooltipStats(const float2& pos, const std::vector<StatDelta>& statDeltas)
    {
    	//...
    
    	if (statDeltas.empty())
    		return;
    
    	// Выбираем тип баббла в зависимости от количества статов, которые в нём нужно отобразить.
    	// Баббл с последним статом "wish chance" выглядит немного не так, как остальные,
    	// но возможен (пока что) только для варианта с тремя статами.
    
    	Bubble* const bubblesNormal[] =
    	{
    		&m_bubbleTooltipStats1SE,
    		&m_bubbleTooltipStats2SE,
    		&m_bubbleTooltipStats3SE,
    		&m_bubbleTooltipStats4SE
    	};
    	Bubble* const bubblesWish[] =
    	{
    		nullptr,
    		nullptr,
    		&m_bubbleTooltipStats3SE_Wish,
    		nullptr
    	};
    
    	Bubble* const* const bubbles = (statDeltas.end() == std::find_if(statDeltas.begin(), statDeltas.end(),
    		[](const StatDelta& delta) -> bool { return delta.first == PS_WishChance; }))
    			? bubblesNormal : bubblesWish;
    	
    	Bubble& bubble = *bubbles[(statDeltas.size() <= ARRAY_SIZE(bubbles)) ? (statDeltas.size() - 1) : (ARRAY_SIZE(bubbles) - 1)];
    	if (&bubble == nullptr)
    	{
    		RZT_LOG_WARNING("Bubble with %d stats with wish chance is not supported!", statDeltas.size());
    		return;
    	}
    
    	// Настраиваем выбранный баббл.
    
    	//... (здесь вызываются всякие методы через ссылку bubble)
    }

    Внезапные изменения в спецификации такие внезапные.
    Мне всегда становится страшно, когда из-за них я начинаю рожать что-то подобное.

    Kirinyale, 31 Марта 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    std::string get(const std::string& name) {
          NamedPropertyMap::iterator it = properties.find(name);
          if (it == properties.end())
            return false;
    
          std::string ret;
          it->second->Get(ret);
          return ret;
        }

    return false; компилится на ура в VS2008

    Aleskey, 30 Марта 2011

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

    +159

    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
    m_hSemaphore		= CreateSemaphore( NULL, 1, 1, NULL );
    ....
    
    void CTestGUIDlg::OnBnClickedButtonStartStream()
    {
    	WaitForSingleObject(m_hSemaphore, INFINITE);
    	if(m_ThreadHandle)
    	{
    		AfxMessageBox("Stop running stream!", MB_ICONEXCLAMATION);
    		return;
    	};
    
    	m_ThreadHandle	= NULL;
    	m_StreamType	= 1;
    	m_ThreadHandle =					(HANDLE)_beginthreadex(NULL,
    										0,
    										streamProcedure,
    										static_cast<LPVOID>( this ),
    										0,
    										NULL);	
    
    	if(!m_ThreadHandle) 
    	{
    		m_StreamType	= 0;
    	}
    	UpdateButtons();
    	ReleaseSemaphore(m_hSemaphore, 1, NULL);
    }

    классика жанра

    Aleskey, 30 Марта 2011

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