aboutsummaryrefslogtreecommitdiff
path: root/magnets.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-03-31 20:38:31 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-03-31 20:45:37 +0100
commit91735e5019be84d2fa693c5d40746c818ace28f8 (patch)
treed45177442b311cf1d567b959ca08be12d8564cd2 /magnets.c
parent1af1204b9c33c9c03b2e0fe66c2f07d9729cbc72 (diff)
downloadpuzzles-91735e5019be84d2fa693c5d40746c818ace28f8.zip
puzzles-91735e5019be84d2fa693c5d40746c818ace28f8.tar.gz
puzzles-91735e5019be84d2fa693c5d40746c818ace28f8.tar.bz2
puzzles-91735e5019be84d2fa693c5d40746c818ace28f8.tar.xz
Correct a range check in Magnets' layout verification
Squares in the grid are numbered from 0, so the upper limit check needs to use "<=" rather than "<". Without this, invalid descriptions can cause a read overrun off the end of the board.
Diffstat (limited to 'magnets.c')
-rw-r--r--magnets.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/magnets.c b/magnets.c
index d190848..d95d146 100644
--- a/magnets.c
+++ b/magnets.c
@@ -520,7 +520,7 @@ nextchar:
* (i.e. each end points to the other) */
for (idx = 0; idx < state->wh; idx++) {
if (state->common->dominoes[idx] < 0 ||
- state->common->dominoes[idx] > state->wh ||
+ state->common->dominoes[idx] >= state->wh ||
state->common->dominoes[state->common->dominoes[idx]] != idx) {
*prob = "Domino descriptions inconsistent";
goto done;