summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2017-09-15 22:21:15 +0200
committerGitHub <noreply@github.com>2017-09-15 22:21:15 +0200
commit79c7e218477011f90011e64dc991689d3e4681bd (patch)
treef775fa2b4ee808392c8b56e374daa49656897294
parent25f742cc3d68693c51fbe84ce7bb633f4bb1ae04 (diff)
parent4f16baca43156eb2f8855aeef79b61decf267c52 (diff)
Merge pull request #11078 from hpvb/fix-10717
Don't allow division by false (zero)
-rw-r--r--core/variant_op.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index b6e114b853..be8a8de8b1 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -670,7 +670,34 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
switch (p_a.type) {
DEFAULT_OP_FAIL(NIL);
- DEFAULT_OP_NUM(/, BOOL, _bool);
+ case BOOL: {
+ switch (p_b.type) {
+ case BOOL: {
+ int64_t b = p_b._data._bool;
+ if (b == 0) {
+
+ r_valid = false;
+ _RETURN("Division By False");
+ }
+ _RETURN(p_a._data._bool / b);
+
+ } break;
+ case INT: {
+ int64_t b = p_b._data._int;
+ if (b == 0) {
+
+ r_valid = false;
+ _RETURN("Division By Zero");
+ }
+ _RETURN(p_a._data._bool / b);
+
+ } break;
+ case REAL: _RETURN(p_a._data._bool / p_b._data._real);
+ default: {}
+ }
+ r_valid = false;
+ return;
+ };
case INT: {
switch (p_b.type) {
case BOOL: {