shithub: puzzles

Download patch

ref: 91735e5019be84d2fa693c5d40746c818ace28f8
parent: 1af1204b9c33c9c03b2e0fe66c2f07d9729cbc72
author: Ben Harris <[email protected]>
date: Fri Mar 31 16:38:31 EDT 2023

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.

--- a/magnets.c
+++ b/magnets.c
@@ -520,7 +520,7 @@
      * (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;