build: CMake presets, multi-compiler CI matrix, and foundation OOB fix#10
Merged
Conversation
Add CMakePresets.json with debug, relwithdebinfo and release presets.
The debug preset enables AddressSanitizer + UndefinedBehaviorSanitizer
(with -fno-sanitize-recover so findings fail the run) and hardened
standard-library assertions (_GLIBCXX_ASSERTIONS / _LIBCPP_HARDENING_MODE)
to catch out-of-bounds container access that ASan alone misses.
Rework the CI graph job into a build matrix over {gcc, clang} x
{debug, release} so both compilers and both build types are exercised.
The compiler is selected via CC/CXX so the presets stay compiler-agnostic,
the FetchContent cache is keyed per compiler/preset, and ASLR entropy is
lowered so ASan can map its shadow memory on newer Ubuntu runners.
When pushing a card onto a foundation pile, both waste_to_foundation and tableau_to_foundation linked the moved card's "beneath" pointer to m_foundation_indices[foundation_top]. foundation_top is a card index (0..52) but m_foundation_indices is sized by suit (4), so this read far out of bounds; it should store foundation_top (the previous foundation top) directly. AddressSanitizer did not catch this because the overrun index lands in adjacent in-object array members. The hardened standard-library assertions added with the debug preset flag it immediately.
-Wall/-Werror/-pedantic were appended to the global CMAKE_CXX_FLAGS, so they leaked into third-party FetchContent builds (fmt, nlohmann_json, Catch2). That broke the GCC debug build in CI: GCC 13's <regex> header trips -Werror=maybe-uninitialized while compiling Catch2, code we don't control. Move the flags onto an INTERFACE library (rose_warnings) linked PUBLIC from rose_lib, so only our own targets (rose_lib, rose, unittests) are compiled with them. This also removes the need for the per-Catch2 -Wno-deprecated-literal-operator workaround, which existed for the same reason under AppleClang.
With `on: [push, pull_request]` every PR ran the whole matrix twice (once per event). Restrict the push trigger to the main branch so branch pushes are covered only by the pull_request event, while pushes to main (and the docker job gated on it) still run.
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.
Summary
CMakePresets.jsonwithdebug,relwithdebinfo, andreleasepresets. Thedebugpreset builds with AddressSanitizer + UndefinedBehaviorSanitizer (-fno-sanitize-recoverso findings fail the run) and hardened standard-library assertions (_GLIBCXX_ASSERTIONS/_LIBCPP_HARDENING_MODE), which catch out-of-bounds container access that ASan alone misses.graphjob into a build matrix over{gcc, clang} × {debug, release}, so both compilers and both build types are exercised. Compiler is selected viaCC/CXX(presets stay compiler-agnostic), the FetchContent cache is keyed per compiler/preset, and ASLR entropy is lowered so ASan can map its shadow memory on newer Ubuntu runners.The bug
waste_to_foundationandtableau_to_foundationboth indexed the size-4m_foundation_indicesarray withfoundation_top, a card index (0..52), when linking a card pushed onto a foundation pile. It should storefoundation_topdirectly as the moved card's "beneath" pointer:ASan missed it because the overrun index lands in adjacent in-object array members; the hardened libc++ assertion flagged it on the first test run. This corrupted the foundation-pile linkage, so it's a real logic fix, not just an analyzer complaint.
Testing
All 15 tests pass locally under the
debugpreset (ASan + UBSan + hardened libc++). Both compilers will be exercised by the new CI matrix.