diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-05-03 15:48:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 15:48:49 +0200 |
commit | f9b9992c255434653cc9b2754ed81513a898c5b2 (patch) | |
tree | 1182608c350ed73dec625567dc58eb68d7450d06 | |
parent | 4e06731346543a5129bae57a4d6a08f752bcfba1 (diff) | |
parent | 2cbdcb03a1a5d4b7a1b64ce85892cf655c3e229b (diff) |
Merge pull request #35245 from qarmin/unsigned_bit_shift
Don't allow to use in bit shift negative operands
-rw-r--r-- | core/variant/variant_op.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index 6cbc98d14d..8cfa793c0e 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -257,6 +257,14 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + +#if defined(DEBUG_ENABLED) + if (b < 0 || a < 0) { + *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; + r_valid = false; + return; + } +#endif *r_ret = a << b; r_valid = true; } @@ -276,6 +284,14 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + +#if defined(DEBUG_ENABLED) + if (b < 0 || a < 0) { + *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; + r_valid = false; + return; + } +#endif *r_ret = a >> b; r_valid = true; } |