From 023b1d7f5a60b5833f7e2030fade6cc1cff54eba Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 17 May 2022 14:14:42 -0300 Subject: Implement read-only arrays Arrays can be set as read-only and thus cannot be modified. Assigning the array will create an editable copy. Similar to is already done to read-only dictionaries. --- core/variant/variant_setget.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core/variant/variant_setget.cpp') diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 6514922d01..3839da495f 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -624,6 +624,11 @@ struct VariantIndexedSetGet_Array { PtrToArg::encode(v[index], member); } static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { + if (VariantGetInternalPtr::get_ptr(base)->is_read_only()) { + *valid = false; + *oob = true; + return; + } int64_t size = VariantGetInternalPtr::get_ptr(base)->size(); if (index < 0) { index += size; @@ -638,6 +643,10 @@ struct VariantIndexedSetGet_Array { *valid = true; } static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { + if (VariantGetInternalPtr::get_ptr(base)->is_read_only()) { + *oob = true; + return; + } int64_t size = VariantGetInternalPtr::get_ptr(base)->size(); if (index < 0) { index += size; -- cgit v1.2.3