- 1
void updateEach(void *ptr, void *unused)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+144.8
void updateEach(void *ptr, void *unused)
chipmunk update method
chipmunk - физический движок (типа под iPhone) на сях. Прелесть, правда?
+138.1
sprintf(cmd, "%supd_downloader -p upd_downloader\\bin %s %s -a %s",
#if defined(__unix__)
"./",
#else
"",
#endif
arg1,
option->arg2 ? arg2 : "",
#if defined(__i386__) || defined(_M_X86)
"i686"
#else
"x86_64"
#endif
);
res = run_command(cmd);
Обнаружил в коде. Типа портируемый код =) Да еще и sprintf() ...
+134.8
#include "stdafx.h"
#include "conio.h"
#include "time.h"
#include "stdlib.h"
#include "windows.h"
#include <iostream>
using namespace std;
void go()
{ int m[10],maxi,mini,max,min,temp;
srand(time(NULL));
for(int i=0;i<10;i++)
m[i]=rand()%30;
max=0;
for(int i=0;i<10;i++)
{if(m[i]>max) { max=m[i]; maxi=i;};
}
min=max;
for(int i=0;i<10;i++)
{if(m[i]<min) {min=m[i]; mini=i;};
}
for(int i=0;i<10;i++)
cout<<m[i]<<endl;
m[maxi],m[mini]=m[mini],m[maxi];
temp=m[maxi];
m[maxi]=m[mini];
m[mini]=temp;
cout<<"============"<<endl;
for(int i=0;i<10;i++)
cout<<m[i]<<endl;
cout<<"alala=="<<max<<endl;
cout<<"ololo=="<<min<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
go();
getch();
return 0;
}
хе-хе, друг написал , меняет макс и мин элементы местами)
+100
#include <iostream>
int main(void)
{
for (int i=0;i<600000000;i++)
cout<<"Ten minuters";
//IT Works!
}
Реальный код с cyberforum. Задание звучало как "Написать таймер, каждые 10 минут выводящий какое-нибудь сообщение". Один умник написал такое нечто, от чего я просто впал в ступор.
+136.7
BOOLEAN
KiCheckForAtlThunk (
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context
)
/*++
Routine Description:
This routine will determine whether an access violation was raised due to
an attempt to execute an ATL thunk in a no-execute, non-stack area.
If so, the thunk will be emulated and execution resumed.
Arguments:
ExceptionRecord - Supplies a pointer to an exception record.
Context - Supplies a pointer to a context frame.
Return Value:
TRUE - Context was updated to reflect the emulated ATL thunk, resume
execution.
FALSE - Not an ATL thunk, continue raising the exception.
--*/
//.........
//KiDispatchException:
//......
switch (ExceptionRecord->ExceptionCode) {
case STATUS_BREAKPOINT:
ContextFrame.Eip--;
break;
case KI_EXCEPTION_ACCESS_VIOLATION:
ExceptionRecord->ExceptionCode = STATUS_ACCESS_VIOLATION;
if (PreviousMode == UserMode) {
if (KiCheckForAtlThunk(ExceptionRecord,&ContextFrame) != FALSE) {
goto Handled1;
}
//................
Объявление KiCheckForAtlThunk (втыкать в комменты и название =)) ) Для тех кто в танке: исходники Windows, оконные классы ATL выделяют тупо в хипе кусок-переходник, который заменяет HWND, идущий первым параметром в оконную процедуру, на естественный, объектно-ориентированный this. Так вот, если у нас установлено где-то в реестре юзать защиту от выполнения данных, то, естественно, в хипе хер чего выполнишь, и возникнет #GP, и тут-то нам и придет на помощь KiCheckForAtlThunk =) Короче, ИМХО, вносить изменения в ядро, для того, чтобы нормально работала криво написанная юзермодная библиотека -- та еще жесть =) Все кто минусует -- не шарят :P
+144.9
node_t* read_record(FILE *file) {
int success = 0;
node_t *record = 0;
do {
int nsz, dsz;
record = (node_t*)malloc(sizeof(node_t));
if (!record) {
break;
}
record->data = 0;
record->next = 0;
if (fread(&nsz, sizeof(int), 1, file) != 1 || feof(file)) {
break;
}
if (fread(record->name, 1, nsz, file) != nsz || feof(file)) {
break;
}
/* ... */
record->nsz = nsz;
record->dsz = dsz;
success = 1;
} while (0);
if (record && !success) {
free_list(record);
record = 0;
}
return record;
}
void write_record(FILE *file, node_t *record) {
int dsz = record->dsz;
int nsz = record->nsz;
if ((fwrite(&nsz, sizeof(int), 1, file) != 1) ||
(fwrite(record->name, 1, nsz, file) != nsz) ||
(fwrite(&csz, sizeof(int), 1, file) != 1) ||
(fwrite(record->data, 1, dsz, file) != dsz) ||
ferror(file)) {
fputs("Error: write_record", stderr);
}
}
+92.9
string* newstr()
{
string* str;
return memset(str=malloc(sizeof(string)), 0, str?sizeof(string):0);
}
+138.7
char serverName[MAX_NAME];
char buttonName[MAX_NAME];
char serverIdStr[3];
serverIdStr[2] = '\0';
int currentSpot = 0;
// ...... получение serverName и currentSpot
serverIdStr[0] = '0' + ((currentSpot+1)/10);
serverIdStr[1] = '0' + ((currentSpot+1)%10);
strcpy(buttonName, buttonPrefix);
strcat(buttonName, serverIdStr);
Кто то не знает про существование sprintf...
+144.8
__inline BOOL
SearchOneDirectory(
IN LPSTR Directory,
IN LPSTR FileToFind,
IN LPSTR SourceFullName,
IN LPSTR SourceFilePart,
OUT PBOOL FoundInTree
)
{
//
// This was way too slow. Just say we didn't find the file.
//
*FoundInTree = FALSE;
return(TRUE);
}
Оптимизация Microsoft. Найдено в исходниках Windows, утекших в 2004.
+144.8
__inline BOOL
SearchOneDirectory(
IN LPSTR Directory,
IN LPSTR FileToFind,
IN LPSTR SourceFullName,
IN LPSTR SourceFilePart,
OUT PBOOL FoundInTree
)
{
//
// This was way too slow. Just say we didn't find the file.
//
*FoundInTree = FALSE;
return(TRUE);
}
Оптимизация by Microsoft. Шедевр из утёкших в 2004 году исходников Windows, заставило посмеятся, веселые у Микрософта заглушки