From 46e5311d5a384907817ca1b60281d04d1f0bd5e1 Mon Sep 17 00:00:00 2001 From: Mario Liebisch Date: Fri, 10 Mar 2023 17:26:34 +0100 Subject: [PATCH] Fixed read-only dictionaries adding missing keys When querying a non-existing key on a read-only dictionary, the key was still added (albeit never set). This fixes #74726. --- core/variant/dictionary.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp index 0429508cc54..7ab150a4f84 100644 --- a/core/variant/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -83,7 +83,12 @@ Variant &Dictionary::operator[](const Variant &p_key) { if (unlikely(_p->read_only)) { if (p_key.get_type() == Variant::STRING_NAME) { const StringName *sn = VariantInternal::get_string_name(&p_key); - *_p->read_only = _p->variant_map[sn->operator String()]; + const String &key = sn->operator String(); + if (_p->variant_map.has(key)) { + *_p->read_only = _p->variant_map[key]; + } else { + *_p->read_only = Variant(); + } } else { *_p->read_only = _p->variant_map[p_key]; }