diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-03-18 15:10:37 +0100 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-04-22 13:57:34 +0200 |
commit | ec29c3e784abdf891abd38f42444216e3d2a0fb7 (patch) | |
tree | dad1726991dc9138786ed0cbd6b22532c648bec0 /core/variant | |
parent | 7529c0bec597d70bc61975a82063bb5112ac8879 (diff) | |
download | redot-engine-ec29c3e784abdf891abd38f42444216e3d2a0fb7.tar.gz |
[Core] Fix property access on read-only `Dictionary`
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/variant_setget.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 9d5ed22b1a..f49e9e54b3 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -251,15 +251,21 @@ void Variant::set_named(const StringName &p_member, const Variant &p_value, bool return; } } else if (type == Variant::DICTIONARY) { - Variant *v = VariantGetInternalPtr<Dictionary>::get_ptr(this)->getptr(p_member); + Dictionary &dict = *VariantGetInternalPtr<Dictionary>::get_ptr(this); + + if (dict.is_read_only()) { + r_valid = false; + return; + } + + Variant *v = dict.getptr(p_member); if (v) { *v = p_value; - r_valid = true; } else { - VariantGetInternalPtr<Dictionary>::get_ptr(this)->operator[](p_member) = p_value; - r_valid = true; + dict[p_member] = p_value; } + r_valid = true; } else { r_valid = false; } |