Skip to content

Some changes mostly polish and C++ safety - #47

Merged
justinhj merged 3 commits into
masterfrom
polish-changes-1.4.2
Sep 30, 2026
Merged

justinhj merged 3 commits into
masterfrom
polish-changes-1.4.2

Conversation

@justinhj

Copy link
Copy Markdown
Owner

Summary

Pre-release hardening, robustness enhancements, and CI checks for the **v1.4.2** release.

### Key Changes

1. **Rule of 3/5 Copy Prevention (`stlastar.h`, `fsa.h`)**
   - Explicitly deleted copy constructor and copy assignment operator (`= delete`) on both `AStarSearch` and

FixedSizeAllocator.
- Prevents accidental pass-by-value shallow copying of internal raw pointers (m_pMemory, m_Start, m_Goal),
which previously led to double-free crashes on scope exit.

2. **Search Reuse Safety (`stlastar.h`)**
   - In `SetStartAndGoalStates()`, added an automatic cleanup check: if `m_Start != nullptr`, any prior search nodes

are freed before allocating start and goal nodes for the new search.
- Eliminates node leaks when an existing AStarSearch instance is reused without manual calls to
FreeSolutionNodes().

3. **Allocator Underflow Protection (`fsa.h`)**
   - Added an assertion and early exit guard for `MaxElements == 0` to prevent `m_MaxElements - 1` unsigned underflow

in the free-list initialization loop.

4. **Universal Leak Assertion (`stlastar.h`)**
   - Removed the `#if USE_FSA_MEMORY` preprocessor guard from `EnsureMemoryFreed()`.
   - Node allocation balance (`assert(m_AllocateNodeCount == 0)`) is now actively validated in both pool-allocated and

standard heap (#define USE_FSA_MEMORY 0) configurations.

5. **CI Workflow Verification (`.github/workflows/c-cpp.yml`)**
   - Added a `Run Examples` step running `./findpath`, `./minpathbucharest`, and `./8puzzle 013824765` to verify all

sample executables build and run cleanly on every push and PR.

6. **Benchmark Tuning (`bench.cpp`)**
   - Set `NUM_SEARCHES` to 20,000 for practical benchmark runtimes.

7. **Unit Tests (`tests.cpp`)**
   - Added `SetStartAndGoalStates Cleans Up Previous Search On Reuse` to verify leak-free instance reuse.
   - Added `AStarSearch and FixedSizeAllocator Are Non-Copyable` using `<type_traits>` to enforce non-copyability at

compile time.

### Testing
- All 9 unit tests pass cleanly (`ctest --test-dir build --output-on-failure`).
- Verified all example executables run and exit with code 0.

@justinhj
justinhj merged commit cdd1cb1 into master Sep 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant