Undead: check for valid commands in execute_move()

Previously, Undead's execute_move would go into a spin when it
encountered an unexpected command character in a move string.  Now it
rejects the move instead.
This commit is contained in:
Ben Harris
2023-01-07 23:31:25 +00:00
parent 023ce7554c
commit a02c55b049

View File

@ -2080,8 +2080,7 @@ static game_state *execute_move(const game_state *state, const char *move)
if (c == 'S') { if (c == 'S') {
move++; move++;
solver = true; solver = true;
} } else if (c == 'G' || c == 'V' || c == 'Z' || c == 'E' ||
if (c == 'G' || c == 'V' || c == 'Z' || c == 'E' ||
c == 'g' || c == 'v' || c == 'z') { c == 'g' || c == 'v' || c == 'z') {
move++; move++;
sscanf(move, "%d%n", &x, &n); sscanf(move, "%d%n", &x, &n);
@ -2093,13 +2092,11 @@ static game_state *execute_move(const game_state *state, const char *move)
if (c == 'v') ret->pencils[x] ^= 2; if (c == 'v') ret->pencils[x] ^= 2;
if (c == 'z') ret->pencils[x] ^= 4; if (c == 'z') ret->pencils[x] ^= 4;
move += n; move += n;
} } else if (c == 'D' && sscanf(move + 1, "%d,%d%n", &x, &y, &n) == 2 &&
if (c == 'D' && sscanf(move + 1, "%d,%d%n", &x, &y, &n) == 2 &&
is_clue(ret, x, y)) { is_clue(ret, x, y)) {
ret->hints_done[clue_index(ret, x, y)] ^= 1; ret->hints_done[clue_index(ret, x, y)] ^= 1;
move += n + 1; move += n + 1;
} } else if (c == 'M') {
if (c == 'M') {
/* /*
* Fill in absolutely all pencil marks in unfilled * Fill in absolutely all pencil marks in unfilled
* squares, for those who like to play by the rigorous * squares, for those who like to play by the rigorous
@ -2110,6 +2107,10 @@ static game_state *execute_move(const game_state *state, const char *move)
if (ret->guess[i] == 7) if (ret->guess[i] == 7)
ret->pencils[i] = 7; ret->pencils[i] = 7;
move++; move++;
} else {
/* Unknown move type. */
free_game(ret);
return NULL;
} }
if (*move == ';') move++; if (*move == ';') move++;
} }