- 1
- 2
- 3
- 4
- 5
- 6
- 7
void ProgressBar::ProgressBarText::GetBackground()
{
ShowWindow(SW_HIDE);
m_backbrush.~CBrushT();
m_background.~CBitmapT();
ShowWindow(SW_SHOWNORMAL);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+168
void ProgressBar::ProgressBarText::GetBackground()
{
ShowWindow(SW_HIDE);
m_backbrush.~CBrushT();
m_background.~CBitmapT();
ShowWindow(SW_SHOWNORMAL);
}
Разбирался в классе контрола,чувака который его написал. Стало интересно что же он курил когда так называл метод и вызывал в нем деструкторы.
+156
while(myBot.loop) {
sleep(15);
myBot.connect(false);
while(myBot.loop) {
if(myBot.client->recv( 750000 )!=ConnNoError) {
break;
} else {
hostent * record = gethostbyname(myBot.client->server().c_str());
if(record == NULL) {
break;
}
}
}
myBot.disconnect();
}
Бот на gloox. В строчках с 5 по 14 проверяется, не пропал ли линк, и пытается реконнектится, если, собственно, пропал.
+160
void log(string srv, string text) {
time_t rawtime; tm * ptm; time ( &rawtime ); ptm = gmtime ( &rawtime );
ofstream logfile(LOG, ios::app);
logfile << (ptm->tm_year+1900) << "-" << (ptm->tm_mon+1) << "-" << ptm->tm_mday << " "
<< (ptm->tm_hour+MSD%24) << ":" << ptm->tm_min << ":" << ptm->tm_sec << endl << srv << ":\t" << text << endl << endl;
logfile.close();
}
Жистоке, брутальне логирование.
+155
typedef unsigned char byte;
byte masks[] =
{
0,
0x1,
0x3,
0x7,
0xF,
0x1F,
0x3F,
0x7F,
0xFF
};
class RegionBool
{
public:
RegionBool(unsigned int width, unsigned int height) : w_(width), h_(height), arr_(0), lineLenBytes_(0)
{
double lineLenBytes = 0; // байт на строку
byte strLenAddBits = static_cast<byte>(modf(static_cast<double>(w_) / 8, &lineLenBytes) * 8);
lineLenBytes_ = static_cast<long>(lineLenBytes) + ((strLenAddBits > 0) ? 1 : 0);
long bytes = lineLenBytes_ * h_;
arr_ = new byte[bytes];
memset(arr_, 0, bytes);
}
virtual ~RegionBool()
{
delete[] arr_;
}
inline byte* createLineMask(int x, int w)
{
// Hey! Attention, animal! Me is you. Listen: you can replace "masks[i]" with "(0xFF >> (8-i))". ХЗ, хав ит фастер.
byte* mask = new byte[lineLenBytes_];
memset(mask, 0, lineLenBytes_);
double skipBytes = 0;
byte startSkipBits = static_cast<byte>(modf(static_cast<double>(x) / 8, &skipBytes) * 8);
byte* pmask = mask + static_cast<int>(skipBytes);
byte before = (startSkipBits) ? (8 - startSkipBits) : 0;
if (before > w)
*pmask |= (masks[w] << startSkipBits);
else
{
if (before)
*pmask++ |= (masks[before] << startSkipBits);
double fillBytes = 0;
byte after = static_cast<byte>(modf(static_cast<double>(w - before) / 8, &fillBytes) * 8);
if (fillBytes)
{
memset(pmask, 0xFF, static_cast<int>(fillBytes));
pmask += static_cast<int>(fillBytes);
}
if (after)
*pmask |= masks[after];
}
return mask;
}
virtual void OR(int x, int y, unsigned int w, unsigned int h)
{
byte* mask = createLineMask(x,w);
unsigned int lim = y + h;
byte* cur = arr_ + (y * lineLenBytes_);
for (unsigned int ty = y; ty < lim; ty++)
{
byte* m = mask;
for (int i = 0; i < lineLenBytes_; i++)
*cur++ |= *m++;
}
delete[] mask;
}
private:
long lineLenBytes_;
unsigned int w_;
unsigned int h_;
unsigned char* arr_;
};
Простите, что много букв.
Подобие региона, в котором пиксель представлен битом. Операции предполагаются только с прямоугольниками, подразумевается, что прямоугольники вмещаются в регион.
Рассказывайте мне про меня))
+142
string a = "Hello World!";
printf("%s", a);
+163
typedef char char_array_2 [2] ;
typedef char char_array_3 [3] ;
typedef char char_array_22[32];
/* ... */
if( 0 == (purpose = new char_array_3[ dArraySize ] ) )
{
ALLOC_ERROR();
}
if( 0 == (mode = new char_array_3[ dArraySize ] ) )
{
ALLOC_ERROR();
}
if( 0 == (state = new char_array_2[ dArraySize ] ) )
{
ALLOC_ERROR();
}
if( 0 == (referencedate = new char_array_22[ dArraySize ] ) )
{
ALLOC_ERROR();
}
/* и еще десяток в таком же стиле */
С++ в (болгарские) массы. и пусть только попробуют сказать что мы ошибок выделения памяти не обрабатываем.
ЗЫ самый прикол что код который этой памятью пользуется 100% совместим с std::vector<std::string>. хотя я бы лично все строки в структуру загнал (и структуры в вектор) бо 10+ массивов это говно.
+163
foo(int objType)
{
std:string sObjType;
char outStr[256];
memset(outStr,NULL,256);
sprintf(outStr,"0x%x",(unsigned int)objType);
sObjType = outStr;
//…
std::ostringstream str;
str << "Ready: list of objects, type " << sObjType;
TRACE(str.str());
}
+152
bool Pl::load(QString &path){
if(path.isEmpty()){
return false;
}
QFile file(path);
if(!file.exists()){
return false;
}
file.open(QIODevice::ReadOnly | QIODevice::Text);
file.setTextModeEnabled(true);
if(!file.isOpen()){
return false;
}
QString str;
QString title;
while(file.bytesAvailable() > 0){
str = QString::fromUtf8(file.readLine(1024).trimmed());
if(str.isEmpty()){
continue;
}
else{
if(str.at(0) == '#' && title.isEmpty()){
if(str.left(10) == "#EXTINF:0,"){
title = str.mid(10);
}
else{
title = "";
}
}
}
if(this->addTrack(str, title)){
title = "";
}
else{
QUrl _u(str);
if(this->addURL(_u, title)){
title = "";
}
}
}
file.close();
return true;
}
Некий кусок кода для парсинга m3u от товарища POPSul
+157
struct Vertex
{
float x, y, z;
float tu0, tv0;
} vertices[20000] =
{
-X, 0, Z, 0, 0,
X, 0, Z, 0, 0,
-X, 0, -Z, 0, 0,
X, 0, -Z, 0, 0,
0, Z, X, 0, 0,
0, Z, -X, 0, 0,
0, -Z, X, 0, 0,
0, -Z, -X, 0, 0,
Z, X, 0, 0, 0,
-Z, X, 0, 0, 0,
Z, -X, 0, 0, 0,
-Z, -X, 0, 0, 0,
};
+151
std::string wbfunc(std::string& hash)
{
std::string line;
std::ifstream f("/home/hromjo/q");
int l = 0;
while (std::getline(f, line))
{
std::cout << "Перебор: " << l << "паролей." << "\n";
l++;
if (md5(line) == hash)
{
return line;
break;
}
}
}
Возможно слегка не в тему.
Писал я и хочу проверить, говнокод ли это.
И что можно исправить в этом говнокоде.