summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Liebisch <mario.liebisch@gmail.com>2023-03-10 17:26:34 +0100
committerMario Liebisch <mario.liebisch@gmail.com>2023-03-10 17:26:34 +0100
commit46e5311d5a384907817ca1b60281d04d1f0bd5e1 (patch)
tree02d8e32eabd625af465e5a32da7973890089afb2
parentd8e242cba8fe33f2d4e3c3e4d5f08038ab063888 (diff)
downloadredot-engine-46e5311d5a384907817ca1b60281d04d1f0bd5e1.tar.gz
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.
-rw-r--r--core/variant/dictionary.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp
index 0429508cc5..7ab150a4f8 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];
}