add assertions after many unchecked dynamic casts

These were all reported by coverity, and indeed seem to have been
assumed to work without failing at runtime.
This commit is contained in:
Chris Beck 2014-11-19 00:21:41 -05:00
parent d27aab7439
commit f5e2204326
4 changed files with 12 additions and 3 deletions

View file

@ -811,6 +811,8 @@ void create_engine::set_current_level(const size_t index)
random_map* current_random_map =
dynamic_cast<random_map*>(&current_level());
assert(current_random_map); // if dynamic cast has failed then we somehow have gotten all the pointers mixed together.
generator_.reset(current_random_map->create_map_generator());
} else {
generator_.reset(NULL);

View file

@ -368,6 +368,8 @@ void create::process_event()
ng::scenario* current_scenario =
dynamic_cast<ng::scenario*>(&engine_.current_level());
assert(current_scenario);
players << current_scenario->num_players();
map_size << _("Size: ") << current_scenario->map_size();
@ -378,6 +380,8 @@ void create::process_event()
ng::campaign* current_campaign =
dynamic_cast<ng::campaign*>(&engine_.current_level());
assert(current_campaign);
players << current_campaign->min_players();
if (current_campaign->max_players() !=
current_campaign->min_players()) {

View file

@ -96,12 +96,12 @@ twidget::~twidget()
void twidget::set_id(const std::string& id)
{
tcontrol* this_ctrl = dynamic_cast<tcontrol*>(this);
DBG_GUI_LF
<< "set id of " << static_cast<void*>(this) << " to '" << id << "' "
<< "(was '" << id_ << "'). Widget type: "
<< (dynamic_cast<tcontrol*>(this)
? dynamic_cast<tcontrol*>(this)->get_control_type()
: typeid(twidget).name()) << "\n";
<< (this_ctrl ? this_ctrl->get_control_type() : typeid(twidget).name()) << "\n";
id_ = id;
}

View file

@ -2781,6 +2781,9 @@ static int intf_debug_ai(lua_State *L)
//so set up a dummy engine
ai::ai_composite * ai_ptr = dynamic_cast<ai::ai_composite *>(c);
assert(ai_ptr);
ai::ai_context& ai_context = ai_ptr->get_ai_context();
config cfg = ai::configuration::get_default_ai_parameters();