mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Cleanly reject more ill-formed solve moves in Flood
The fix in e4112b3 was incomplete: there was another assertion that could be failed by a save file with an ill-formed solve move. That now gets rejected properly. Here's an example save file to demonstrate the problem: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection GAME :5:Flood PARAMS :7:6x6c6m0 CPARAMS :7:6x6c6m0 DESC :39:000000000000000000000000000000000000,00 NSTATES :1:2 STATEPOS:1:2 MOVE :1:S
This commit is contained in:
13
flood.c
13
flood.c
@ -938,15 +938,16 @@ static game_state *execute_move(const game_state *state, const char *move)
|
|||||||
|
|
||||||
sol->moves = snewn(sol->nmoves, char);
|
sol->moves = snewn(sol->nmoves, char);
|
||||||
for (i = 0, p = move; i < sol->nmoves; i++) {
|
for (i = 0, p = move; i < sol->nmoves; i++) {
|
||||||
assert(*p);
|
if (!*p) {
|
||||||
|
badsolve:
|
||||||
|
sfree(sol->moves);
|
||||||
|
sfree(sol);
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
sol->moves[i] = atoi(p);
|
sol->moves[i] = atoi(p);
|
||||||
p += strspn(p, "0123456789");
|
p += strspn(p, "0123456789");
|
||||||
if (*p) {
|
if (*p) {
|
||||||
if (*p != ',') {
|
if (*p != ',') goto badsolve;
|
||||||
sfree(sol->moves);
|
|
||||||
sfree(sol);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user