- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
for (int i=0;i<16;i++)
{
if ((rbuf[i+1]>>16)!=(1<<i))
{
break;
res=SOME_ERROR;
}
};
/* in another function */
DWORD * rbuf =new DWORD[Size];
...
if (rbuf!=NULL) free(rbuf);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+132
for (int i=0;i<16;i++)
{
if ((rbuf[i+1]>>16)!=(1<<i))
{
break;
res=SOME_ERROR;
}
};
/* in another function */
DWORD * rbuf =new DWORD[Size];
...
if (rbuf!=NULL) free(rbuf);
Вот такими библиотеками пользуются клиенты некоторых фирм ;)
+104
#ifdef _DEBUG
if ( !
#endif
dt_time_sprintf_current( tbuf, sizeof(tbuf), false )
#ifdef _RELEASE
;
#else
)
{
fprintf( stderr, "-- unable to get current time\n" );
}
#endif
}
#ifdef _DEBUG
;(
+132
#define COMMAND_MARKER '\x1B'
#define COMMAND_SET '='
#define COMMAND_XOR '^'
#define COMMAND_OR '|'
#define COMMAND_AND '&'
void usbWriteOut(uchar *data, int len)
{
while(len--) {
uchar c = *data;
buf[0] = buf[1];
buf[1] = buf[2];
buf[2] = buf[3];
buf[3] = c;
if(buf[0] == COMMAND_MARKER) {
uint8_t val = (hex2u(buf[2]) << 4) | hex2u(buf[3]);
if(buf[1] == COMMAND_SET) {
colorData = val;
}
else if(buf[1] == COMMAND_XOR) {
colorData ^= val;
}
else if(buf[1] == COMMAND_OR) {
colorData |= val;
}
else if(buf[1] == COMMAND_AND) {
colorData &= ~val;
}
}
}
}
Простой баг оказался крайне подлым!
При тестировании девайса терминалкой и чепятании команды ручками, каждый символ уходил в отдельном пакете и создавалось впечатление, что всё работает.
После чего девайс был собран с применением большого количества термоклея, так что исправление бага оказалось совершенно непростым занятием >_<
+131
struct tm lpstTimeRecordRet;
struct tm lpstTimeRecord;
lpstTimeRecordRet = *localtime_r ( &potiUnixTime, &lpstTimeRecord);
*фейс палм*
+131
#include <stdio.h>
#include <math.h>
void out_bin (unsigned short c){
for (int i = 11; i>=0; i--) {
if ((c & (unsigned short)(1<<i))/(1<<i)==1) printf("1");
else printf("0");
}
printf("\n");
}
int main (){
int a[8]={2,4,5,6,8,9,10,11};
int b[4]={0,1,3,7};
int d=0;
unsigned short int c=0,c1[4]={0,0,0,0};
unsigned char data=165,tdata=176;
for(int i=7;i>=0;i--)
{
if (tdata & 128){
c+=(unsigned short )(1<<a[i]);
}
tdata<<=1;
}
for (int i=0;i<8;i++){
unsigned short b = (unsigned short)((c & (unsigned short)(1<<a[i]))/(1<<a[i])) ;
if(a[i] & 1) c1[0]^=b;
else
if(a[i] & 2) c1[1]^=b ;
else
if(a[i] & 4) c1[2]^=b ;
else
if(a[i] & 8) c1[3]^=b ;
}
for (int i = 0; i < 4; i++) {
if (!c1[i]) {
c|=(unsigned short)(1<<((1<<i)-1));
}
}
printf("Data= ");
out_bin(c);
c ^= 256 ;
if ((((c & 1024)/1024) ^ ((c & 256)/256) ^ ((c & 64)/64) ^ ((c & 16)/16) ^ ((c & 4)/4) ^ ((c & 1)/1) ) !=1 ){
d += 1;
}
if ((((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 4)/4) ^ ((c & 2)/2) ) !=1 ){
d +=2;
}
if ((((c & 2048)/2048) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 16)/16) ^ ((c & 8)/8) ) !=1 ){
d +=4;
}
if ((((c & 2048)/2048) ^ ((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 256)/256) ^ ((c & 128)/128) )!=1 ){
d+=8;
}
printf("Spoiled= ");
out_bin(c);
printf("%d",d);
if (d){
c ^=(1<<(d-1));
}
printf("Corrected= ");
out_bin(c);
return 0;
}
Код Хэмминга
+132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <time.h>
char a[150],c[150];
int main(int argc, char **argv) {
FILE * tmp;
while(1) {
int b=0,b1=0;
bool A=0;
tmp=fopen(".tmp.txt","r");
fgets(c,150,tmp);
fclose(tmp);
system("rm .tmp.txt");
system("xwininfo -tree -root | grep -i '\\- deadbeef-0.5.1' > .tmp.txt");
tmp=fopen(".tmp.txt","r");
fgets(a,150,tmp);
fclose(tmp);
for(int i=16;i<149;i++) {
c[i-16]=c[i];
a[i-16]=a[i];
if(a[i-16]=='-')
b++;
if(c[i-16]=='-')
b1++;
if(b==2)
a[i-16]=0;
if(b1==2)
c[i-16]=0;
}
for(int j=0;j<(int)strlen(c);j++) {
if (a[j]!=c[j]) A=true;
}
if (A) {
char lamp[]="/usr/bin/purple-remote \"setstatus?status=available&message=";
strcat(lamp,a);
strcat(lamp,"\"");
system(lamp);
}
sleep(5);
}
return 0;
}
Реализация аналога pidgin-musictracker для deadbeef
+139
#include "stdio.h"
#include "string.h"
int main (int argc, char *argv[])
{
FILE * f1= fopen("новый файл","r");
char a[3];
char * b= &a[0];
int i=0;
for (i = 0; i < 80; i ++)
{
char a1[400]="java -jar TextCode.jar ";
char a2[40]="/home/dan/Education/Subj/MFCIT/roz/";
fscanf(f1,"%s",b);
strcat(a1,a2);
strcat(a1,b);
strcat(a1,"/");
strcat(a1,b);
strcat(a1," ");
strcat(a1,a2);
strcat(a1,b);
strcat(a1,"/");
strcat(a1,b);
strcat(a1,".c ");
strcat(a1,a2);
strcat(a1,b);
strcat(a1,"/");
strcat(a1,b);
strcat(a1,".cod");
system(a1);
}
return 0;
}
Шифрует тексты при помощи проги на Java
+136
static BOOL CALLBACK callbackEspecial(
LPSTR aModuleName,
DWORD aModuleBase,
ULONG aModuleSize,
PVOID aUserContext)
{
BOOL retval = TRUE;
DWORD addr = *(DWORD*)aUserContext;
/*
* You'll want to control this if we are running on an
* architecture where the addresses go the other direction.
* Not sure this is even a realistic consideration.
*/
const BOOL addressIncreases = TRUE;
/*
* If it falls inside the known range, load the symbols.
*/
if (addressIncreases
? (addr >= aModuleBase && addr <= (aModuleBase + aModuleSize))
: (addr <= aModuleBase && addr >= (aModuleBase - aModuleSize))
) {
retval = _SymLoadModule(GetCurrentProcess(), NULL, aModuleName, NULL, aModuleBase, aModuleSize);
}
return retval;
}
аццкая адресация
http://mozilla-thunderbird.sourcearchive.com/documentation/1.5.0.10-0ubuntu3/nsStackFrameWin_8cpp-source.html
+135
try {
// ....
} except(EXCEPTION_EXECUTE_HANDLER) {
Err = ERROR_INVALID_PARAMETER;
//
// Access the following variables here so that the compiler will respect our statement
// ordering w.r.t. these values. Otherwise, we can't be sure that the values are accurate
// at the point where the exception occurred.
//
Buffer = Buffer;
Array = Array;
i = i;
}
втф?
+142
static inline gboolean is_alt(const gchar* string)
{
return ((string[0] == '<') &&
(string[1] == 'a' || string[1] == 'A') &&
(string[2] == 'l' || string[2] == 'L') &&
(string[3] == 't' || string[3] == 'T') &&
(string[4] == '>'));
}
static inline gboolean is_ctl (const gchar* string)
{
return ((string[0] == '<') &&
(string[1] == 'c' || string[1] == 'C') &&
(string[2] == 't' || string[2] == 'T') &&
(string[3] == 'l' || string[3] == 'L') &&
(string[4] == '>'));
}
static inline gboolean is_modx(const gchar* string)
{
return ((string[0] == '<') &&
(string[1] == 'm' || string[1] == 'M') &&
(string[2] == 'o' || string[2] == 'O') &&
(string[3] == 'd' || string[3] == 'D') &&
(string[4] >= '1' && string[4] <= '5') &&
(string[5] == '>'));
}
static inline gboolean is_ctrl(const gchar* string)
{
return ((string[0] == '<') &&
(string[1] == 'c' || string[1] == 'C') &&
(string[2] == 't' || string[2] == 'T') &&
(string[3] == 'r' || string[3] == 'R') &&
(string[4] == 'l' || string[4] == 'L') &&
(string[5] == '>'));
}
static inline gboolean is_shft (const gchar* string)
{
return ((string[0] == '<') &&
(string[1] == 's' || string[1] == 'S') &&
(string[2] == 'h' || string[2] == 'H') &&
(string[3] == 'f' || string[3] == 'F') &&
(string[4] == 't' || string[4] == 'T') &&
(string[5] == '>'));
}
// ... (ещё 100500 подобных функций)
// ... а тем временем где-то ниже:
if (len >= 9 && is_release (accelerator))
{
accelerator += 9;
len -= 9;
mods |= EGG_VIRTUAL_RELEASE_MASK;
}
else if (len >= 9 && is_control (accelerator))
{
accelerator += 9;
len -= 9;
mods |= EGG_VIRTUAL_CONTROL_MASK;
}
else if (len >= 9 && is_primary (accelerator))
{
accelerator += 9;
len -= 9;
mods |= EGG_VIRTUAL_CONTROL_MASK;
}
else if (len >= 7 && is_shift (accelerator))
{
accelerator += 7;
len -= 7;
mods |= EGG_VIRTUAL_SHIFT_MASK;
}
else if (len >= 6 && is_shft (accelerator))
{
accelerator += 6;
len -= 6;
mods |= EGG_VIRTUAL_SHIFT_MASK;
}
else if (len >= 6 && is_ctrl (accelerator))
{
accelerator += 6;
len -= 6;
mods |= EGG_VIRTUAL_CONTROL_MASK;
}
// ... и так далее. код целиком сюда просто не влезет.
шедевр. что сравнение строк, что цепочка if-else. все хороши.
полной версией можно насладиться тут:
https://github.com/mate-desktop/mate-control-center/blob/master/capplets/keybindings/eggaccelerators.c