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:
Josiah VanderZee 2024-04-22 06:58:32 -05:00
parent eb432d3da0
commit f14f8e484e
1 changed files with 8 additions and 1 deletions

View File

@ -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) {