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:
@@ -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};
|
||||||
|
|||||||
Reference in New Issue
Block a user