From 694ee1bf5237cc298813862d09375b25527f56e4 Mon Sep 17 00:00:00 2001 From: Rindbee Date: Mon, 5 Dec 2022 20:24:22 +0800 Subject: Fix suppressed error message on error when using % format string Before, the valid flag would always be true. On formatting errors, an error message is returned as the result. (No error prompts.) --- core/variant/variant_op.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/core/variant/variant_op.h b/core/variant/variant_op.h index ec1ce67445..34858540ec 100644 --- a/core/variant/variant_op.h +++ b/core/variant/variant_op.h @@ -890,10 +890,12 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const String &a = *VariantGetInternalPtr::get_ptr(&p_left); *r_ret = do_mod(a, &r_valid); - r_valid = true; } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - *VariantGetInternalPtr::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr::get_ptr(left), nullptr); + bool valid = true; + String result = do_mod(*VariantGetInternalPtr::get_ptr(left), &valid); + ERR_FAIL_COND_MSG(!valid, result); + *VariantGetInternalPtr::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { PtrToArg::encode(do_mod(PtrToArg::convert(left), nullptr), r_ret); @@ -913,10 +915,12 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const String &a = *VariantGetInternalPtr::get_ptr(&p_left); *r_ret = do_mod(a, *VariantGetInternalPtr::get_ptr(&p_right), &r_valid); - r_valid = true; } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - *VariantGetInternalPtr::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr::get_ptr(left), *VariantGetInternalPtr::get_ptr(right), nullptr); + bool valid = true; + String result = do_mod(*VariantGetInternalPtr::get_ptr(left), *VariantGetInternalPtr::get_ptr(right), &valid); + ERR_FAIL_COND_MSG(!valid, result); + *VariantGetInternalPtr::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { PtrToArg::encode(do_mod(PtrToArg::convert(left), PtrToArg::convert(right), nullptr), r_ret); @@ -939,10 +943,12 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const String &a = *VariantGetInternalPtr::get_ptr(&p_left); *r_ret = do_mod(a, p_right.get_validated_object(), &r_valid); - r_valid = true; } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - *VariantGetInternalPtr::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr::get_ptr(left), right->get_validated_object(), nullptr); + bool valid = true; + String result = do_mod(*VariantGetInternalPtr::get_ptr(left), right->get_validated_object(), &valid); + ERR_FAIL_COND_MSG(!valid, result); + *VariantGetInternalPtr::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { PtrToArg::encode(do_mod(PtrToArg::convert(left), PtrToArg::convert(right), nullptr), r_ret); @@ -965,10 +971,12 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const String &a = *VariantGetInternalPtr::get_ptr(&p_left); *r_ret = do_mod(a, *VariantGetInternalPtr::get_ptr(&p_right), &r_valid); - r_valid = true; } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - *VariantGetInternalPtr::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr::get_ptr(left), *VariantGetInternalPtr::get_ptr(right), nullptr); + bool valid = true; + String result = do_mod(*VariantGetInternalPtr::get_ptr(left), *VariantGetInternalPtr::get_ptr(right), &valid); + ERR_FAIL_COND_MSG(!valid, result); + *VariantGetInternalPtr::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { PtrToArg::encode(do_mod(PtrToArg::convert(left), PtrToArg::convert(right), nullptr), r_ret); -- cgit v1.2.3