mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Mosaic: fault out-of-bounds moves in execute_move()
Returning NULL in this case is better than dereferencing it.
This commit is contained in:
8
mosaic.c
8
mosaic.c
@ -1297,6 +1297,10 @@ static game_state *execute_move(const game_state *state, const char *move)
|
||||
return new_state;
|
||||
}
|
||||
cell = get_coords(new_state, new_state->cells_contents, x, y);
|
||||
if (cell == NULL) {
|
||||
sfree(new_state);
|
||||
return NULL;
|
||||
}
|
||||
if (*cell >= STATE_OK_NUM) {
|
||||
*cell &= STATE_OK_NUM;
|
||||
}
|
||||
@ -1363,6 +1367,10 @@ static game_state *execute_move(const game_state *state, const char *move)
|
||||
for (i = 0; i < diff; i++) {
|
||||
cell = get_coords(new_state, new_state->cells_contents,
|
||||
x + (dirX * i), y + (dirY * i));
|
||||
if (cell == NULL) {
|
||||
sfree(new_state);
|
||||
return NULL;
|
||||
}
|
||||
if ((*cell & STATE_OK_NUM) == 0) {
|
||||
*cell = last_state;
|
||||
update_board_state_around(new_state, x + (dirX * i),
|
||||
|
Reference in New Issue
Block a user