summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2023-02-24 13:43:55 -0300
committerGeorge Marques <george@gmarqu.es>2023-02-24 14:06:11 -0300
commited81b165ebb6eba5369d0677ef98429ac2d9a6c9 (patch)
treeb1c97d9266e065051512a22af14a523ba8a69ab7 /core
parentdefa46bfd1d9e391ced336306c93ecdff38a7ce7 (diff)
Make max() and min() global functions only accept numbers
The behavior for those are not well defined for non-numeric arguments. To avoid confusion the other types are forbidden.
Diffstat (limited to 'core')
-rw-r--r--core/variant/variant_utility.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 042ebe368a..8f3ae65b9c 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -543,6 +543,13 @@ struct VariantUtilityFunctions {
Variant base = *p_args[0];
Variant ret;
for (int i = 1; i < p_argcount; i++) {
+ Variant::Type arg_type = p_args[i]->get_type();
+ if (arg_type != Variant::INT && arg_type != Variant::FLOAT) {
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.expected = Variant::FLOAT;
+ r_error.argument = i;
+ return Variant();
+ }
bool valid;
Variant::evaluate(Variant::OP_LESS, base, *p_args[i], ret, valid);
if (!valid) {
@@ -576,6 +583,13 @@ struct VariantUtilityFunctions {
Variant base = *p_args[0];
Variant ret;
for (int i = 1; i < p_argcount; i++) {
+ Variant::Type arg_type = p_args[i]->get_type();
+ if (arg_type != Variant::INT && arg_type != Variant::FLOAT) {
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.expected = Variant::FLOAT;
+ r_error.argument = i;
+ return Variant();
+ }
bool valid;
Variant::evaluate(Variant::OP_GREATER, base, *p_args[i], ret, valid);
if (!valid) {