Mines: forbid moves that flag or unflag an exposed square

interpret_move() couldn't generate them, but execute_move() also needs
to forbid them to defend against corrupt save files.  I don't think this
actually caused any crashes, but it did cause unexpected "1" squares not
adjacent to mines.
This commit is contained in:
Ben Harris
2023-02-01 17:07:12 +00:00
parent 37df1f2bbc
commit 1736445518

View File

@ -2701,7 +2701,9 @@ static game_state *execute_move(const game_state *from, const char *move)
while (*move) { while (*move) {
if (move[0] == 'F' && if (move[0] == 'F' &&
sscanf(move+1, "%d,%d", &cx, &cy) == 2 && sscanf(move+1, "%d,%d", &cx, &cy) == 2 &&
cx >= 0 && cx < from->w && cy >= 0 && cy < from->h) { cx >= 0 && cx < from->w && cy >= 0 && cy < from->h &&
(ret->grid[cy * from->w + cx] == -1 ||
ret->grid[cy * from->w + cx] == -2)) {
ret->grid[cy * from->w + cx] ^= (-2 ^ -1); ret->grid[cy * from->w + cx] ^= (-2 ^ -1);
} else if (move[0] == 'O' && } else if (move[0] == 'O' &&
sscanf(move+1, "%d,%d", &cx, &cy) == 2 && sscanf(move+1, "%d,%d", &cx, &cy) == 2 &&