mirror of https://github.com/minetest/minetest.git
Fix MSVC warning C4172 in ModifySafeMap::get
We may have been returning a reference to a temporary caused by a ternary expression. To be safe, this converts the ternary into an if conditional so that no conversions will happen during the evaluation of the return expression.
This commit is contained in:
parent
eb432d3da0
commit
f14f8e484e
|
@ -369,7 +369,14 @@ public:
|
|||
return it->second;
|
||||
}
|
||||
auto it = m_values.find(key);
|
||||
return it == m_values.end() ? null_value : it->second;
|
||||
// This conditional block was converted from a ternary to ensure no
|
||||
// temporary values are created in evaluating the return expression,
|
||||
// which could cause a dangling reference.
|
||||
if (it != m_values.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
return null_value;
|
||||
}
|
||||
}
|
||||
|
||||
void put(const K &key, const V &value) {
|
||||
|
|
Loading…
Reference in New Issue