Skip to content

Fix crash when re-entering exhausted generator after earlier sections - #3237

Open
akasakariko wants to merge 1 commit into
catchorg:develfrom
akasakariko:fix-2809-exhausted-generator
Open

akasakariko wants to merge 1 commit into
catchorg:develfrom
akasakariko:fix-2809-exhausted-generator

Conversation

@akasakariko

Copy link
Copy Markdown

Description

When earlier SECTION blocks take more test cycles than a following GENERATE has elements, GeneratorTracker finishes advancing and exhausts its underlying IGenerator before those sections finish running
In a later cycle, execution reaches GENERATE again while GeneratorTracker::isComplete() is true, and Catch::Generators::generate dereferences the exhausted generator via get(), causing out-of-bounds access and a fatal error

This change:

  • Tracks generator exhaustion via m_isExhausted on GeneratorTracker when countedNext() returns false
  • Recreates the underlying generator on re-entry in RunContext::createGeneratorTracker while keeping the tracker in CompletedSuccessfully and updating the current tracker so nested GENERATE calls remain aligned
  • Keeps nested generators created under an already completed GeneratorTracker in CompletedSuccessfully without reopening the parent tracker
  • Adds a regression test and updates approval baselines

GitHub Issues

Closes #2809

When preceding sections take more cycles than a following GENERATE has
elements, GeneratorTracker completes and exhausts its underlying
generator before all sibling sections finish. Re-entering GENERATE in a
later cycle then dereferences the exhausted generator.

Track exhaustion on GeneratorTracker, reset the underlying generator on
re-entry while keeping CompletedSuccessfully, and handle nested
generators created under an already completed tracker.

Closes catchorg#2809
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.27273% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.30%. Comparing base (a1a991f) to head (31de213).

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3237      +/-   ##
==========================================
- Coverage   91.41%   91.30%   -0.11%     
==========================================
  Files         205      205              
  Lines        9106     9139      +33     
==========================================
+ Hits         8324     8344      +20     
- Misses        782      795      +13     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Generator results into a fatal error in 2.13.9 (newest not tested)

1 participant