From 5782e29db43034574763b1d10c48486c3e95f0d2 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 9 Jan 2023 20:24:15 +0000 Subject: [PATCH] Tracks: make sure moves are valid in execute_move() Tracks allowed moves in execute_move() that shouldn't have been allowed, like changing the state of the edges of the board. This moves couldn't be generated by interpret_move(), but could be loaded from a save file. Now execute_move() uses the same ui_can_flip_*() functions as interpret_move() to decide whether a particular move is allowed. This should prevent some assertion failures when loading corrupted save files. --- tracks.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tracks.c b/tracks.c index 674be4a..443a62a 100644 --- a/tracks.c +++ b/tracks.c @@ -2429,6 +2429,8 @@ static game_state *execute_move(const game_state *state, const char *move) f = (c == 'T' || c == 't') ? S_TRACK : S_NOTRACK; if (d == 'S') { + if (!ui_can_flip_square(ret, x, y, f == S_NOTRACK)) + goto badmove; if (c == 'T' || c == 'N') ret->sflags[y*w+x] |= f; else @@ -2438,6 +2440,8 @@ static game_state *execute_move(const game_state *state, const char *move) unsigned df = 1<