aboutsummaryrefslogtreecommitdiff
path: root/tracks.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-09 20:24:15 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commit5782e29db43034574763b1d10c48486c3e95f0d2 (patch)
tree55d341a03b2dd46f673cb560a8b97fcb198579f4 /tracks.c
parent15974d06bbaad287382c6eeb8deb7c6f3a627278 (diff)
downloadpuzzles-5782e29db43034574763b1d10c48486c3e95f0d2.zip
puzzles-5782e29db43034574763b1d10c48486c3e95f0d2.tar.gz
puzzles-5782e29db43034574763b1d10c48486c3e95f0d2.tar.bz2
puzzles-5782e29db43034574763b1d10c48486c3e95f0d2.tar.xz
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.
Diffstat (limited to 'tracks.c')
-rw-r--r--tracks.c4
1 files changed, 4 insertions, 0 deletions
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<<i;
if (MOVECHAR(df) == d) {
+ if (!ui_can_flip_edge(ret, x, y, df, f == S_NOTRACK))
+ goto badmove;
if (c == 'T' || c == 'N')
S_E_SET(ret, x, y, df, f);
else