From ce39d0a4d051d14071ef658c8d5cd86a8eb8b22f Mon Sep 17 00:00:00 2001 From: Codex instance Date: Thu, 30 Jul 2026 16:50:19 +0100 Subject: [PATCH] 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 --- main.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.cc b/main.cc index c71cae1..55e69f0 100644 --- a/main.cc +++ b/main.cc @@ -297,10 +297,11 @@ namespace { sqs.push_back(sq); pos = grid.next_pos(pos + idx); - idx = grid.largest_square(pos, n); // Have we reached the end? If so success! if (pos == grid.end()) { break; } + + idx = grid.largest_square(pos, n); } return {length, sqs};