Fix several null pointer checks done after first use

This commit is contained in:
Ignacio R. Morelle 2015-08-19 02:07:43 -03:00
parent 1f50e28023
commit 056189d1c6
4 changed files with 13 additions and 9 deletions

View file

@ -753,6 +753,8 @@ void save_preview_pane::draw_contents()
}
}
assert(game_config_ && "ran into a null game config pointer inside a game preview pane");
std::string map_data = summary["map_data"];
if(map_data.empty()) {
const config &scenario = game_config_->find_child(summary["campaign_type"], "id", summary["scenario"]);
@ -774,8 +776,6 @@ void save_preview_pane::draw_contents()
LOG_DP << "When parsing save summary " << ((*info_)[index_]).name() << std::endl
<< "Did not find a map_data field. Looking in game config for a child [" << summary["campaign_type"] << "] with id " << summary["scenario"] << std::endl;
assert(game_config_ && "ran into a null game config pointer inside a game preview pane");
const std::map<std::string,surface>::const_iterator itor = map_cache_.find(map_data);
if(itor != map_cache_.end()) {
map_surf = itor->second;

View file

@ -60,7 +60,10 @@ static lg::log_domain log_engine("engine");
static lg::log_domain log_enginerefac("enginerefac");
#define LOG_RG LOG_STREAM(info, log_enginerefac)
static void show_carryover_message(saved_game& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level, const LEVEL_RESULT res){
static void show_carryover_message(saved_game& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level, const LEVEL_RESULT res)
{
assert(resources::teams);
bool has_next_scenario = !resources::gamedata->next_scenario().empty() &&
resources::gamedata->next_scenario() != "null";
//maybe this can be the case for scenario that only contain a story and end during the prestart event ?
@ -83,7 +86,6 @@ static void show_carryover_message(saved_game& gamestate, playsingle_controller&
report << _("You have been defeated!") << "\n";
}
assert(resources::teams);
//We need to write the carryover amount to the team thats why we need non const
std::vector<team>& teams = *resources::teams;
int persistent_teams = 0;

View file

@ -178,12 +178,13 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
const int side = lexical_cast<int>(change["side"]);
const size_t index = side - 1;
assert(resources::gameboard);
if(index >= resources::gameboard->teams().size()) {
ERR_NW << "Bad [change_controller] signal from server, side out of bounds: " << change.debug() << std::endl;
return PROCESS_CONTINUE;
}
assert(resources::gameboard);
const team & tm = resources::gameboard->teams().at(index);
const std::string &player = change["player"];
const bool was_local = tm.is_local();

View file

@ -411,6 +411,8 @@ config &scoped_wml_variable::store(const config &var_value)
scoped_wml_variable::~scoped_wml_variable()
{
assert(resources::gamedata);
if(activated_) {
resources::gamedata->clear_variable_cfg(var_name_);
BOOST_FOREACH(const config &i, previous_val_.child_range(var_name_))
@ -425,10 +427,9 @@ scoped_wml_variable::~scoped_wml_variable()
}
LOG_NG << "scoped_wml_variable: var_name \"" << var_name_ << "\" has been reverted.\n";
}
if (resources::gamedata) {
assert(resources::gamedata->scoped_variables.back() == this);
resources::gamedata->scoped_variables.pop_back();
}
assert(resources::gamedata->scoped_variables.back() == this);
resources::gamedata->scoped_variables.pop_back();
}
void scoped_xy_unit::activate()