Don't allow to use in bit shift negative operands

This commit is contained in:
Rafał Mikrut 2021-02-09 16:14:50 +01:00
parent df9c98e107
commit 2cbdcb03a1

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