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:
parent
d27aab7439
commit
f5e2204326
4 changed files with 12 additions and 3 deletions
|
@ -811,6 +811,8 @@ void create_engine::set_current_level(const size_t index)
|
|||
random_map* current_random_map =
|
||||
dynamic_cast<random_map*>(¤t_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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue