solver: check completion before probing square

next_pos() returns the grid end sentinel when a placement completes the board. Avoid passing that sentinel to largest_square(), which requires an in-range position and otherwise reads past the grid.

Tests: Debug, Release, ASan, and UBSan CTest suites

Refs: #14
This commit was merged in pull request #19.
This commit is contained in:
Codex instance
2026-07-30 16:50:19 +01:00
parent ccdcf03fa8
commit ce39d0a4d0
+2 -1
View File
@@ -297,10 +297,11 @@ namespace {
sqs.push_back(sq); sqs.push_back(sq);
pos = grid.next_pos(pos + idx); pos = grid.next_pos(pos + idx);
idx = grid.largest_square(pos, n);
// Have we reached the end? If so success! // Have we reached the end? If so success!
if (pos == grid.end()) { break; } if (pos == grid.end()) { break; }
idx = grid.largest_square(pos, n);
} }
return {length, sqs}; return {length, sqs};