Fix a nullref if an unknown unit type is present in the statistics

Found by coverity
This commit is contained in:
Alexander van Gessel 2013-12-08 00:23:38 +01:00
parent 923e85b773
commit 20b0f3ac94

View file

@ -28,6 +28,7 @@
static lg::log_domain log_engine("engine");
#define DBG_NG LOG_STREAM(debug, log_engine)
#define ERR_NG LOG_STREAM(err, log_engine)
namespace {
@ -628,7 +629,12 @@ int sum_cost_str_int_map(const stats::str_int_map &m)
{
int cost = 0;
for (stats::str_int_map::const_iterator i = m.begin(); i != m.end(); ++i) {
cost += i->second * unit_types.find(i->first)->cost();
const unit_type *t = unit_types.find(i->first);
if (!t) {
ERR_NG << "Statistics refer to unknown unit type '" << i->first << "'. Discarding.\n";
} else {
cost += i->second * t->cost();
}
}
return cost;