From f14f8e484ec4135b4399116548a30765349da205 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Mon, 22 Apr 2024 06:58:32 -0500 Subject: [PATCH] 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. --- src/util/container.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/container.h b/src/util/container.h index a6e302e2c..6e45ef208 100644 --- a/src/util/container.h +++ b/src/util/container.h @@ -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) {