Merge pull request #35245 from qarmin/unsigned_bit_shift

Don't allow to use in bit shift negative operands
This commit is contained in:
Rémi Verschelde 2021-05-03 15:48:49 +02:00 committed by GitHub
commit f9b9992c25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

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