mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-10 01:26:35 +00:00
Fix a nullref if an unknown unit type is present in the statistics
Found by coverity
This commit is contained in:
parent
923e85b773
commit
20b0f3ac94
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
static lg::log_domain log_engine("engine");
|
static lg::log_domain log_engine("engine");
|
||||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||||
|
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -628,7 +629,12 @@ int sum_cost_str_int_map(const stats::str_int_map &m)
|
|||||||
{
|
{
|
||||||
int cost = 0;
|
int cost = 0;
|
||||||
for (stats::str_int_map::const_iterator i = m.begin(); i != m.end(); ++i) {
|
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;
|
return cost;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user