Don't segfault on premature solve moves in Mines

If a save file contained a solve move as the first move, Mines would
dereference a null pointer trying to look up the (at that point
undetermined) mine locations.  Now execute_move() politely returns
NULL instead.

This save file demonstrates the problem:

SAVEFILE:41:Simon Tatham's Portable Puzzle Collection
VERSION :1:1
GAME    :5:Mines
PARAMS  :5:3x3n0
CPARAMS :5:3x3n0
DESC    :127:r0,u,7a142789cabddc3fc4dcb7d2baa4a4937b33c9613ea870ac098e217981ad339930af585557d62048ea745d05b01475d9699596b394cc0adeebf0440a02
UI      :2:D0
TIME    :1:0
NSTATES :1:2
STATEPOS:1:2
SOLVE   :1:S
This commit is contained in:
Ben Harris
2023-01-28 19:34:28 +00:00
parent e4112b322e
commit 28671e76b7

View File

@ -2637,6 +2637,7 @@ static game_state *execute_move(const game_state *from, const char *move)
if (!strcmp(move, "S")) { if (!strcmp(move, "S")) {
int yy, xx; int yy, xx;
if (!from->layout->mines) return NULL; /* Game not started. */
ret = dup_game(from); ret = dup_game(from);
if (!ret->dead) { if (!ret->dead) {
/* /*