Procházet zdrojové kódy

Test limits before accessing the array (coverity)

tags/v0.99.beta19
Pascal Terjan pterjan před 11 roky
rodič
revize
2ec11a8d96
1 změnil soubory, kde provedl 14 přidání a 14 odebrání
  1. +14
    -14
      examples/conio.c

+ 14
- 14
examples/conio.c Zobrazit soubor

@@ -150,40 +150,40 @@ BOOLEAN isWon(int who, int xsquare[Y_BOARD][X_BOARD])
for(y=0; y<Y_BOARD; y++)
{
/*horizontal position*/
if( xsquare[y][x] == who &&
if( (x+3)<X_BOARD &&
xsquare[y][x] == who &&
xsquare[y][x+1] == who &&
xsquare[y][x+2] == who &&
xsquare[y][x+3] == who &&
(x+3)<X_BOARD
xsquare[y][x+3] == who
)
return TRUE;

/*vertical position*/
if( xsquare[y][x] == who &&
if( (y+3)<Y_BOARD &&
xsquare[y][x] == who &&
xsquare[y+1][x] == who &&
xsquare[y+2][x] == who &&
xsquare[y+3][x] == who &&
(y+3)<Y_BOARD
xsquare[y+3][x] == who
)
return TRUE;

/*downstair diagonal position*/
if( xsquare[y][x] == who &&
if( (x+3)<X_BOARD &&
(y+3)<Y_BOARD &&
xsquare[y][x] == who &&
xsquare[y+1][x+1] == who &&
xsquare[y+2][x+2] == who &&
xsquare[y+3][x+3] == who &&
(x+3)<X_BOARD &&
(y+3)<Y_BOARD
xsquare[y+3][x+3] == who
)
return TRUE;

/*upstair diagonal position*/
if( xsquare[y][x] == who &&
if( (x+3)<X_BOARD &&
(y-3)>=0 &&
xsquare[y][x] == who &&
xsquare[y-1][x+1] == who &&
xsquare[y-2][x+2] == who &&
xsquare[y-3][x+3] == who &&
(x+3)<X_BOARD &&
(y-3)>=0
xsquare[y-3][x+3] == who
)
return TRUE;
}


Načítá se…
Zrušit
Uložit