- 1
- 2
- 3
- 4
int main(int Argcina, char** Argvina) {
int tse_odna_strana_dlya_vseh = (char**)Argcina - Argvina;
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
int main(int Argcina, char** Argvina) {
int tse_odna_strana_dlya_vseh = (char**)Argcina - Argvina;
return 0;
}
0
switch (lol) {
case E::Foo:
return 1;
case E::Bar:
default:
return 0;
case E::Baz:
return 2;
}
Вы знали, что так можно?
Надо запустить пиваса.
+2
// В преддверии нового года на сайте PVS-Studio увеличилось количества C++ говнокода.
// Во-первых, вышла подбора багов за год, а во-вторых, квиз на поиск багов.
// Первый пример кода из квиза для разминки:
void UObject::setDeltaPitch(const UMatrix &gizmo) {
....
if (_fpzero(amount, eps))
return
rotateAccum.setAnglesXYZ(axis);
....
}
Если заинтересовались, то приятного чтения и удачи в поисках говнокодистых багов. Вас ждёт говнокод первого сорта.
Топ 10 ошибок в C и С++ проектах в 2023 году - https://pvs-studio.ru/ru/blog/posts/cpp/1092/
С++ квиз от PVS-Studio и Сергея Кушниренко - https://pvs-studio.ru/ru/blog/quest/kushnirenko_quiz/
А если что-то останется непонятным в квизе, то есть его разбор - https://pvs-studio.ru/ru/blog/posts/cpp/1091/
С наступающим НГ!
0
// Конкурс для C++ программистов от команды PVS-Studio
// Уникальная возможность получить приз за говнокод с багом!
// https://habr.com/ru/companies/pvs-studio/articles/775388/
Поделитесь своим кодом с ошибкой и участвуйте в розыгрыше 10 книг "Вредные советы для C++ программистов". Подробности в публикации на Хабре: Конкурс для C++ программистов и их любимых багов - https://habr.com/ru/companies/pvs-studio/articles/775388/
0
bool isDate(int d, int m, int y)
{
return m > 0 && m < 13 ? d > 0 && d < 29 + (m - 2 ? 2 + (m + m / 8) % 2 : !(y % 4) && (y % 100) || !(y % 400)) : 0;
}
+1
void text::draw()
{
CmdWinGUI::draw();
COORD temp = startCo; //Разный мусор
COORD tempEnd = startCo;
int16_t _al = 0;
int16_t _an = 0;
int16_t remain = 0;
uint8_t a = 0;
bool fullRow = 1; //Флаги, не изменять
bool alignPrepare = 0;
if (tableLine)
{
temp.Y = temp.Y + lineShift + sepShift;
}
if (!tableFormat)
{
if (alignSetting == ALIGN_C)
{
_al = sizeCo.X/2;
for (uint8_t a = 0;a < 0xFF;++a) //Измеряем длину текстового поля
{
if (textBuffer[a] == NULL)
break;
++remain;
}
temp.X=startCo.X+ _al-remain/2; //Корректируем курсор в соответствии с расчётами
if (temp.X < startCo.X) //Если предыдущие вычисления дали ошибку - выход за предел рамки слева
temp.X = startCo.X; //Корректируем
}
for (;;)
{
SetConsoleCursorPosition(hCon, temp);
if (textBuffer[a] == NULL)
break;
printf("%c", textBuffer[a]);
++temp.X;
++a;
if (temp.X == startCo.X + sizeCo.X - 1) //Проверяем достигло ли рамки, иначе обрываем цикл
break;
}
return;
}
for (uint8_t b = 0;b<=filledRows;++b)
{
if (!fullRow)
{
temp.X = tempEnd.X;
}
tempEnd.X += tableRowSize[b] - 1;
if (alignSetting == ALIGN_C)
{
--temp.X;
//Предварительные расчеты смещения
if (!alignPrepare)
{
for (SHORT a = temp.X;a < 0xFF;++a)
{
if (a == tempEnd.X) //Проверяем достигло ли рамки, иначе обрываем цикл
{
--_an;
break; //половина длины поля таблицы
}
++_an;
}
for (uint8_t a = 0;a < 0xFF;++a)
{
if (tableText[b][a] == NULL)
{
_al = a; //половина длины слова
break;
}
}
alignPrepare = 1; //Подымаем флаг готовности
}
//Коррекция положения курсора в соответствии с результатами блока предварительных расчётов
temp.X += abs(_an / 2) - abs(_al / 2);
_an = 0;
}for (;;){
SetConsoleCursorPosition(hCon, temp); //Ставим курсор в начало/середину/конец поля
if (tableText[b][a] == NULL)
{
fullRow = 0; //При окончании поля текста до заполнения поля снимаем флаг заполнения поля
break;
}
++temp.X;
if (temp.X == tempEnd.X) //Проверяем достигло ли рамки, иначе обрываем цикл
{
fullRow = 1; //При окончании поля в таблице до завершения поля текста прекращаем вывод и выходим из цикла
break;
}
printf("%c", tableText[b][a]);
++a;
}
a = 0;
alignPrepare = 0; //Сбрасываем флаг для следующей итерации
}
if (isChanged)
this->editFlagSwitch();
}
Рендер текста с учётом коллизии слева и справа
+1
#include "Windows.h"
void line::draw()
{
CmdWinGUI::draw();
uint8_t modB = 0; //modeByte
COORD tempSt = lineStart;
COORD tempEn = lineEnd;
SHORT dX = abs(lineEnd.X - lineStart.X);
SHORT dY = abs(lineEnd.Y - lineStart.Y);
SHORT sX = lineStart.X < lineEnd.X ? 1 : -1;
SHORT sY = lineStart.Y < lineEnd.Y ? 1 : -1;
SHORT dErr = dX - dY;
SHORT dErr2 = 0;
if (scan)
{
SetConsoleCursorPosition(hCon, lineStart);
for (uint8_t a = 0;a <= lineEnd.X-lineStart.X;++a)
{
modB = lineAtrBuffer[a];
SetConsoleTextAttribute(hCon, modB);
printf("%c", lineSymBuffer[a]);
}
if (isChanged)
this->editFlagSwitch();
return;
}
for (;;)
{
SetConsoleCursorPosition(hCon, tempSt);
printf("%c", lineSym);
if (tempSt.X == tempEn.X&&tempSt.Y == tempEn.Y)
break;
dErr2 = dErr * 2;
if (dErr2 > -dY)
{
dErr -= dY;
tempSt.X += sX;
}
if (dErr2 < dX)
{
dErr += dX;
tempSt.Y += sY;
}
}
if (isChanged)
this->editFlagSwitch();
}
Отрисовка произвольной графической линии в консоли
0
char *SomeGlobalPointer {};
void foo()
{
SomeGlobalPointer = new char[1024];
}
int main()
{
foo();
if (!SomeGlobalPointer)
{
delete[] SomeGlobalPointer;
}
return 0;
}
Отсюдова:
https://pvs-studio.ru/ru/blog/posts/cpp/1068/
0
auto objs = it.get_objects();
switch(objs.size())
{
case 1: sent = _out_stream.send_message(objs[0]);
break;
case 2: sent = _out_stream.send_message(objs[0], objs[1]);
break;
case 3: sent = _out_stream.send_message(objs[0], objs[1], objs[2]);
break;
case 4: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3]);
break;
case 5: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4]);
break;
case 6: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5]);
break;
case 7: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6]);
break;
case 8: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7]);
break;
case 9: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8]);
break;
case 10: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9]);
break;
case 11: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10]);
break;
case 12: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11]);
break;
case 13: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12]);
break;
case 14: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13]);
break;
case 15: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13], objs[14]);
break;
case 16: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13], objs[14], objs[15]);
break;
case 17: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13], objs[14], objs[15], objs[16]);
break;
case 18: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13], objs[14], objs[15], objs[16], objs[17]);
break;
case 19: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13], objs[14], objs[15], objs[16], objs[17],
objs[18]);
break;
case 20: sent = _out_stream.send_message(objs[0], objs[1], objs[2], objs[3], objs[4], objs[5],
objs[6], objs[7], objs[8], objs[9], objs[10], objs[11],
objs[12], objs[13], objs[14], objs[15], objs[16], objs[17],
objs[18], objs[19]);
break;
default:
fprintf(stderr, "error: Too much attached objects (%lu), talk to developer\n", objs.size());
return false;
}
if (!sent)
{
fprintf(stderr, "error: Unable to send message to output pipe\n");
return false;
}
Меня заставили это сделать, потому что по задумке число вложенных объектов известно на этапе разработки, а у меня - нет.
0
const uint8_t DexFile::kDexMagic[] = { 'd', 'e', 'x', '\n' };
const uint8_t DexFile::kDexMagicVersions[DexFile::kNumDexVersions][DexFile::kDexVersionLen] = {
{'0', '3', '5', '\0'},
// Dex version 036 skipped because of an old dalvik bug on some versions of android where dex
// files with that version number would erroneously be accepted and run.
{'0', '3', '7', '\0'}
};
Отсюдова:
https://android.googlesource.com/platform/art/+/refs/heads/nougat-release/runtime/dex_file.cc