Skip to content

Commit

Permalink
Merge pull request #78083 from CleverRaven/fix-map-erase-UB-0.I
Browse files Browse the repository at this point in the history
Stash mission ids and remove them after loop for 0.I
  • Loading branch information
esotericist authored Nov 23, 2024
2 parents 3e42c35 + caf4768 commit 8ff5859
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ bool mission::on_creature_fusion( Creature &fuser, Creature &fused )
return false;
}
bool mission_transfered = false;
std::vector<int> mission_ids_to_remove;
for( const int mission_id : mon_fused->mission_ids ) {
const mission *const found_mission = mission::find( mission_id );
if( !found_mission ) {
Expand All @@ -269,10 +270,13 @@ bool mission::on_creature_fusion( Creature &fuser, Creature &fused )
if( type->goal == MGOAL_KILL_MONSTER || type->goal == MGOAL_KILL_MONSTERS ) {
// the fuser has to be killed now!
mon_fuser->mission_ids.emplace( mission_id );
mon_fused->mission_ids.erase( mission_id );
mission_ids_to_remove.push_back( mission_id );
mission_transfered = true;
}
}
for( const int mission_id : mission_ids_to_remove ) {
mon_fused->mission_ids.erase( mission_id );
}
return mission_transfered;
}

Expand Down

0 comments on commit 8ff5859

Please sign in to comment.