Skip to content

Commit

Permalink
Don't dereference iterator after invalidating it
Browse files Browse the repository at this point in the history
Found by coverity.
  • Loading branch information
AI0867 committed Mar 23, 2014
1 parent ae34792 commit 7df83c2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/whiteboard/recall.cpp
Expand Up @@ -139,18 +139,19 @@ void recall::apply_temp_modifier(unit_map& unit_map)
std::vector<unit>& recalls = resources::teams->at(team_index()).recall_list();
std::vector<unit>::iterator it = find_if_matches_id(recalls, temp_unit_->id());
assert(it != recalls.end());
recalls.erase(it);

// Temporarily insert unit into unit_map
//unit map takes ownership of temp_unit
unit_map.insert(temp_unit_.release());

//Add cost to money spent on recruits.
int cost = resources::teams->at(team_index()).recall_cost();
if (it->recall_cost() > -1) {
cost = it->recall_cost();
}

recalls.erase(it);

// Temporarily insert unit into unit_map
//unit map takes ownership of temp_unit
unit_map.insert(temp_unit_.release());

resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(cost);
// Update gold in top bar
resources::screen->invalidate_game_status();
Expand Down

0 comments on commit 7df83c2

Please sign in to comment.