Skip to content

Formation: guard setLeader's find against an empty active range#19

Merged
ivan-ushakov merged 1 commit into
crossplatformfrom
fix/formation-setleader-crash
Jul 19, 2026
Merged

Formation: guard setLeader's find against an empty active range#19
ivan-ushakov merged 1 commit into
crossplatformfrom
fix/formation-setleader-crash

Conversation

@ivan-ushakov

Copy link
Copy Markdown
Collaborator

No description provided.

FormationUnits::setLeader ran find(begin()+1, inactive(), leader) with no
guard on the active range. inactive() is begin()+firstInactive_; when there
are no active units (firstInactive_==0) inactive()==begin(), so the range is
find(begin()+1, begin()) -- first > last. std::find walks forward looking for
last and runs off the end of the heap, the reported EXC_BAD_ACCESS (fault
address 0xc25c00000, a MALLOC_SMALL region boundary), reached via
UnitLegionary::Kill -> UnitActing::finishUpgrade.

Guard the find with activeSize() > 0 (makeAllActive avoids the same trap only
because it first sets firstInactive_ = size()). Also compare the result against
inactive(), the range's end, rather than end(): find returns inactive() when
the leader is not among the active units, and inactive() != end() whenever
inactive units follow -- the old `it != end()` check would then swap an
inactive unit to the front.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ivan-ushakov
ivan-ushakov merged commit 1347327 into crossplatform Jul 19, 2026
4 checks passed
@ivan-ushakov
ivan-ushakov deleted the fix/formation-setleader-crash branch July 19, 2026 07:28
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