- 1
- 2
- 3
- 4
- 5
GNET::ChatBroadCast::~ChatBroadCast(&cbc);
}
else if ( v9 > 9 && v9 == 14 )
{
v4 = this->roleid;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+140
GNET::ChatBroadCast::~ChatBroadCast(&cbc);
}
else if ( v9 > 9 && v9 == 14 )
{
v4 = this->roleid;
Декомпилил тут игруху, а там такое в псевдокоде.
+143
char value[60] = {0};
int data;
snprintf(value, sizeof(value-1), "|%7u\n", data);
coverity полагал что заменить sprintf на snprintf было бы безопаснее
+145
char bStr[1000];
strncpy(bStr, " [\0", strlen(" [\0"));
Потому что в man:
Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null terminated.
+142
#define PHYSICAL unsigned long
#define VIRTUAL unsigned long
прикольное legacy
+133
int main(void)
{
int a=0,b=1000;
int * p;
p=malloc(sizeof(int)*b-7); // уменьшаем выделяемую память на 7 байт, а почему оно не падает?
for(;a<b;a++) p[a]=a;
printf("%lu",sizeof(int)*b);
free(p);
}
а если убрать 8 байт то уже падает,что-то где-то округляется что-ли?
+109
memcpy (stderr, stdout, sizeof (FILE));
+143
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int board[4][4];
void firstblood(); void drawboard(); int turn(); void changeup(); void changedown(); void changeleft(); void changeright(); int numbofpos(); void gameover();
int pow2 ( int n ) { return 1<<n; }
int main ()
{ do{ firstblood(); drawboard(); while ( turn() ); puts("New game? (y,n)"); fflush(stdin); char c=getchar(); if (c!='y') return 0; for (int i=0;i<4;i++) for (int j=0;j<4;j++) board[i][j]=0; } while (1);
}
void firstblood()
{ srand((unsigned int)time); board[rand()%4][rand()%4]=pow2(rand()%3+1); board[rand()%4][rand()%4]=pow2(rand()%4+1); }
void drawboard ()
{ system("CLS"); puts(" 2048 "); int i,j; for (i=0;i<4;i++, printf("\n\n") ) for (j=0;j<4;j++) printf("%5u",board[i][j]); puts("\nw,a,s,d and r to move and new game");
}
int numbofpos()
{ int i,j,n=0; for (i=1;i<4;i++ for (j=0;j<4;j++){if (board[i][j] && board[i][j]==board[i-1][j]) n++; if (board[j][i] && board[j][i]==board[j][i-1]) n++; }for (i=0;i<4;i++) for (j=0;j<4;j++) if (!board[i][j]) n++;
return n ;
}
void gameover()
{
system("CLS"); puts(" 2048 "); int i,j; for (i=0;i<4;i++, printf("\n\n") ) for (j=0;j<4;j++) printf("%5u",board[i][j]); puts("\n Game over ");
}
int turn()
{
char c=getchar(); int i,j,n=0, nulls[16][2];
switch(c)
{ case 'w' : changeup(); break;
case 'a' : changeleft(); break;
case 's' : changedown(); break;
case 'd' : changeright(); break;
case 'r' : return 0;
}
for (i=0;i<4;i++)
for (j=0;j<4;j++)
if ( !board[i][j] ) { nulls[n][0]=i; nulls[n++][1]=j; }
if (n)
{
int t=rand()%n;
board[ nulls[t][0] ][ nulls[t][1] ] = pow2(rand()%2+1);
}
if ( !numbofpos() )
{ gameover(); return 0; }
drawboard();
return 1;
}
void changeleft()
{
int i,j,k;
for (i=0;i<4;i++)
{
int f= ( !board[i][3] )?0:1 ;
for (j=2;j>=0;j--)
{ if (board[i][j] && !f) f=1;
if (!board[i][j] && f==1) { for (k=j+1;k<4;board[i][k-1]=board[i][k],k++); board[i][3]=0; }
}
for (j=0;j<3;j++)
if ( board[i][j] && board[i][j]==board[i][j+1])
{
board[i][j] *= 2;
for (k=j+1;k<3; board[i][k]=board[i][k+1], k++ );
board[i][3]=0;
}
}
}
void changeright()
{
int i,j,k;
for (i=0;i<4;i++)
{
int f= ( !board[i][0] )?0:1 ;
for (j=1;j<4;j++)
{ if (board[i][j] && !f) f=1;
if (!board[i][j] && f==1) { for (k=j;k>0;board[i][k]=board[i][k-1],k--); board[i][0]=0; }
}
for (j=3;j>0;j--)
if ( board[i][j] && board[i][j]==board[i][j-1])
{
board[i][j] *= 2;
for (k=j-1;k>0; board[i][k]=board[i][k-1], k-- );
board[i][0]=0;
}
}
}
void changeup()
{ int i,j,k; for (i=0;i<4;i++) { int f= ( !board[3][i] )?0:1 ; for (j=2;j>=0;j--) { if (board[j][i] && !f) f=1; if (!board[j][i] && f==1) { for (k=j+1;k<4;board[k-1][i]=board[k][i],k++); board[3][i]=0; } }
for (j=0;j<3;j++) if ( board[j][i] && board[j][i]==board[j+1][i]) {board[j][i] *= 2; for (k=j+1;k<3; board[k][i]=board[k+1][i], k++ ); board[3][i]=0; }}}
void changedown()
{int i,j,k; for (i=0;i<4;i++) { int f= ( !board[0][i] )?0:1 ; for (j=1;j<4;j++) { if (board[j][i] && !f) f=1; if (!board[j][i] && f==1) { for (k=j;k>0;board[k][i]=board[k-1][i],k--); board[0][i]=0; } } for (j=3;j>0;j--) if ( board[j][i] && board[j][i]==board[j-1][i]) board[j][i] *= 2;
for (k=j-1;k>0; board[k][i]=board[k-1][i], k-- ); board[0][i]=0;
} }}
2048 только с библиотеками stdio.h, stdlib.h (srand,rand) и time.h (тоже для рандома)
Пожалуйста, уберите ограничение в 100 строк
+124
value += (0<<17); // PARK bit
+143
#include <stdio.h>
int main(void)
{
int d2[3][3][3];
int i,i2,i3;
for(i = 0; i <= 3; ++i)
for(i2 = 0; i2 <= 3; ++i2)
for(i3 = 0; i3 <= 3; ++i3)
d2[i][i2][i3]=5;
i=0,i2=0,i3=0;
for(i = 0; i <= 3; ++i)
for(i2 = 0; i2 <= 3; ++i2)
for(i3 = 0; i3 <= 3; ++i3)
printf("%d\n",d2[i][i2][i3]);
return 0;
}
играюсь я короче с массивом, этот код компилируется,все печатает но в конце Segmentation fault, почему?
gcc -Wall -Wextra -Werror -Wpedantic -ftrapv -fwrapv -fdiagnostics-show-option -std=gnu11 -o "test" "test.c"
+130
char* obrab_stroki(char*, int);
int move(char*);
int action_register(char*);
int speed(char*);
int condition(char*);
char answer1[25];
uint8_t Output[512];
uint32_t number_for_output=16;
typedef struct { char *name; uint8_t adress; } struct_label;
typedef struct { char *name; uint8_t adress; } struct_goto_label;
//----------------------------------------------------------------------------------------
while (strcmp(qwerty[++string_count],""))
{
str=obrab_stroki(qwerty[string_count], 0);
printf("s:%s\n",str);
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"{")) fig_skob++;
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"}")) fig_skob--;
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"{") && !strcmp(str,"if")) { fig_skob_if++; adres_return[fig_skob_if]=number_for_output+3; }
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"}") && fig_skob_if>0) { Output[adres_return[fig_skob_if]]=number_for_output; fig_skob_if--;}
if (fig_skob==0)
{
Output[number_for_output++]=0;
Output[number_for_output++]=0;
}
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,":"))
{
label[number_label].name=qwerty[string_count];
label[number_label++].adress = number_for_output;
continue;
}
//-------------------------------------------------------------------------------------------
if (!strcmp(str,"r")) if (action_register(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
if (!strcmp(str,"move")) if (move(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
if (!strcmp(str,"speed")) if (speed(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
if (!strcmp(str,"if")) if (condition(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
//-----------------------------------------------------------------------------------------
char* obrab_stroki(char* qwerty, int i)
{
int count;
char asnwer1[25];
for (count=0; (qwerty[count+i]<='z' && qwerty[count+i]>='a') || (qwerty[count+i]<='Z' && qwerty[count+i]>='A'); count++)
{
answer1[count]=qwerty[count+i];
}
answer1[count]='\0';
return answer1;
}//тут как бы нет ошибок =)
//----------------------------------------------------------------------------------------------
if (qwerty[i]=='-')
{
if (qwerty[i+1]=='1' && qwerty[i+2]=='0')
{
Output[number_for_output++]=answer|MOTOR_SPEC_SPEED_DEC;
Output[number_for_output++]=0;
return 0;
}
else
return 1;
}
Человек писал компилятор. Самые эпичные моменты