Pages:<< prev 1 next >>
Black Hand

GroupAdministrators
Posts3,708
JoinedJan 1, 2002
I ran a static analysis recently with cppcheck and it picked this up as an out of bound array access in the first set of for loops here. Specifically with board->board[x][y] = 0;
I can't figure out why that would be the case. The compiler doesn't flag it, and it doesn't set off the sanitization code either.
I can't figure out why that would be the case. The compiler doesn't flag it, and it doesn't set off the sanitization code either.
static void init_board( GAME_BOARD_DATA * board )
{
int x, y;
for( x = 0; x < 8; x++ )
for( y = 0; y < 8; y++ )
board->board[x][y] = 0;
board->board[0][0] = WHITE_ROOK;
board->board[0][1] = WHITE_KNIGHT;
board->board[0][2] = WHITE_BISHOP;
board->board[0][3] = WHITE_QUEEN;
board->board[0][4] = WHITE_KING;
board->board[0][5] = WHITE_BISHOP;
board->board[0][6] = WHITE_KNIGHT;
board->board[0][7] = WHITE_ROOK;
for( x = 0; x < 8; x++ )
board->board[1][x] = WHITE_PAWN;
for( x = 0; x < 8; x++ )
board->board[6][x] = BLACK_PAWN;
board->board[7][0] = BLACK_ROOK;
board->board[7][1] = BLACK_KNIGHT;
board->board[7][2] = BLACK_BISHOP;
board->board[7][3] = BLACK_QUEEN;
board->board[7][4] = BLACK_KING;
board->board[7][5] = BLACK_BISHOP;
board->board[7][6] = BLACK_KNIGHT;
board->board[7][7] = BLACK_ROOK;
board->player1 = NULL;
board->player2 = NULL;
board->turn = 0;
board->type = TYPE_LOCAL;
}
Geomancer

GroupAdministrators
Posts1,992
JoinedJul 26, 2005
it doesn't look bad but would it be happier if you did <= 7?
Black Hand

GroupAdministrators
Posts3,708
JoinedJan 1, 2002
<=7 would be functionally equal to < 8 in this case.
Geomancer

GroupAdministrators
Posts1,992
JoinedJul 26, 2005
I agree but never know sometimes that might make one not complain lol depends on what its looking for
It would have been cool if it liked <= 7 but is complaining about < 8.
It would have been cool if it liked <= 7 but is complaining about < 8.
Pages:<< prev 1 next >>