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.
This commit is contained in:
Mario Liebisch 2023-03-10 17:26:34 +01:00
parent d8e242cba8
commit 46e5311d5a
No known key found for this signature in database
GPG Key ID: 32B56AC1F87EFBF9

View File

@ -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];
}