Array out of bounds ?
< Newer Topic
:: Older Topic >
Pages:<< prev 1 next >>
#1 Jan 14, 2025 10:00 pm
Black Hand
GroupAdministrators
Posts3,722
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; }
Pages:<< prev 1 next >>