aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-01 23:00:14 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-01 23:00:14 +0000
commited0e4c304bed990948541fc0cf87309d75653806 (patch)
treea34fe10d20fc0bf1e81a1bd58e84a9fb516ba53b
parent875f0af21fbced5cbf6cf63b86fe3dc51682c863 (diff)
downloadpuzzles-ed0e4c304bed990948541fc0cf87309d75653806.zip
puzzles-ed0e4c304bed990948541fc0cf87309d75653806.tar.gz
puzzles-ed0e4c304bed990948541fc0cf87309d75653806.tar.bz2
puzzles-ed0e4c304bed990948541fc0cf87309d75653806.tar.xz
Fix move validation in Netslide
The maximum length of a column move in Netslide is the height of the puzzle, and the maximum length of a row move is the width, not the other way around. Moves of absolute length more than 1 can't be generated by interpret_move(), but they can come from save files. On non-square grids, the incorrect check led to assertion failures: "0 <= tx && tx < w" and "0 <= ty && ty < h". This save file demonstrates the problem: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection GAME :8:Netslide PARAMS :3:4x9 CPARAMS :3:4x9 DESC :39:0000000000000h0h0000000000000000000000v NSTATES :1:2 STATEPOS:1:2 MOVE :4:R0,5
-rw-r--r--netslide.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/netslide.c b/netslide.c
index 1a01be2..be83b7c 100644
--- a/netslide.c
+++ b/netslide.c
@@ -1137,8 +1137,8 @@ static game_state *execute_move(const game_state *from, const char *move)
if ((move[0] == 'C' || move[0] == 'R') &&
sscanf(move+1, "%d,%d", &c, &d) == 2 &&
c >= 0 && c < (move[0] == 'C' ? from->width : from->height) &&
- d <= (move[0] == 'C' ? from->width : from->height) &&
- d >= -(move[0] == 'C' ? from->width : from->height) && d != 0) {
+ d <= (move[0] == 'C' ? from->height : from->width) &&
+ d >= -(move[0] == 'C' ? from->height : from->width) && d != 0) {
col = (move[0] == 'C');
} else if (move[0] == 'S' &&
strlen(move) == from->width * from->height + 1) {