From 20b0f3ac9415ec8777d0f262ecca33a8ec71bcab Mon Sep 17 00:00:00 2001 From: Alexander van Gessel Date: Sun, 8 Dec 2013 00:23:38 +0100 Subject: [PATCH] Fix a nullref if an unknown unit type is present in the statistics Found by coverity --- src/statistics.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/statistics.cpp b/src/statistics.cpp index 70d16a4cb74..66e42c1ef22 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -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;