Fix out-of-bounds accesses caught by debug-mode assertions - #2250
Merged
cqc-alec merged 1 commit intoOct 1, 2026
Merged
Conversation
With libstdc++ assertions enabled (as in debug builds with GCC 15), two tests aborted: - get_partitioned_paulis_for_largest_first_method took &colour_vec.front() of an empty vector when there are no terms. Use colour_vec.data(), which is valid for an empty vector. - For an empty circuit, LinePlacement asks remove_worst_nodes to remove more nodes than the architecture has, and find_worst_node then calls min_degree on an empty graph, dereferencing the end iterator. Return std::nullopt from find_worst_node when there are no nodes left. Re-enable both tests in debug mode. Fixes Quantinuum#2199.
cqc-alec
self-requested a review
October 1, 2026 14:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The two tests disabled in debug mode for #2199 abort because of real out-of-bounds accesses, not test issues. I reproduced both on GCC 11 by building with
-D_GLIBCXX_ASSERTIONS, which is the check GCC 15 turns on in debug builds.get_partitioned_paulis_for_largest_first_methodtakes&colour_vec.front()of an empty vector when there are no terms. Changed tocolour_vec.data(), which is valid for an empty vector and never read since there are no vertices to colour.interactions_to_linesreturns one empty line, which is dropped and counted as an unused node, soremove_worst_nodesis asked to remove 3 nodes from a 2-node architecture. On the last iterationfind_worst_nodecallsmin_degreeon an empty graph, andstd::min_elementreturns the end iterator, which is then dereferenced.find_worst_nodenow returnsstd::nulloptwhen there are no nodes left, whichremove_worst_nodesalready handles.Both tests are re-enabled in debug mode (the
#ifdef NDEBUGguards are removed).Checked locally:
-D_GLIBCXX_ASSERTIONS, the full C++ suite passes. Reverting either fix on its own makes its test abort again.Bumped
TKET_VERSIONto 2.1.103.Related issues
Fixes #2199.
Checklist