From de8d80dee0042e15eda165f0612f83732107f166 Mon Sep 17 00:00:00 2001 From: JosiahWI <41302989+JosiahWI@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:04:26 -0500 Subject: [PATCH] Fix MSVC warning C4172 in ModifySafeMap::get (#14576) --- 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) {