From 91735e5019be84d2fa693c5d40746c818ace28f8 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 31 Mar 2023 20:38:31 +0100 Subject: [PATCH] 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. --- magnets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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;