X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/81eef9aa2f4506e6bd0610e6b1b0ab3c6bb69467..dddad8fb77a944a470934f7097abe3de91d3b80e:/inertia.c?ds=sidebyside diff --git a/inertia.c b/inertia.c index 2f1fd5d..fc213da 100644 --- a/inertia.c +++ b/inertia.c @@ -304,6 +304,7 @@ static int find_gem_candidates(int w, int h, char *grid, /* * Find the starting square. */ + sx = -1; /* placate optimiser */ for (sy = 0; sy < h; sy++) { for (sx = 0; sx < w; sx++) if (AT(w, h, grid, sx, sy) == START) @@ -369,7 +370,9 @@ static int find_gem_candidates(int w, int h, char *grid, d2 = n; } i2 = (y2*w+x2)*DIRECTIONS+d2; - if (!reachable[i2]) { + if (x2 >= 0 && x2 < w && + y2 >= 0 && y2 < h && + !reachable[i2]) { int ok; #ifdef SOLVER_DIAGNOSTICS printf(" trying point %d,%d,%d", x2, y2, d2);