Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 759a374

Browse files
committed
com.livecode.math: Don't find min/max if error is detected
If the list passed to `MCMathEvalMinMaxList()` is empty or contains non-Number elements, return rather than creating an error and carrying on. This fixes a bug where `kMCNull` was being cast to an `MCNumberRef` and passed to `MCNumberFetchAsReal()`.
1 parent 5dfd2fd commit 759a374

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

libscript/src/module-math.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,16 @@ extern "C" MC_DLLEXPORT_DEF void MCMathEvalMinNumber(MCNumberRef p_left, MCNumbe
343343
static void MCMathEvalMinMaxList(MCProperListRef p_list, bool p_is_min, MCNumberRef& r_output)
344344
{
345345
if (MCProperListIsEmpty(p_list))
346+
{
346347
MCErrorCreateAndThrow(kMCGenericErrorTypeInfo, "reason", MCSTR("list must be non-empty"), nil);
348+
return;
349+
}
347350

348351
if (!MCProperListIsListOfType(p_list, kMCValueTypeCodeNumber))
352+
{
349353
MCErrorCreateAndThrow(kMCGenericErrorTypeInfo, "reason", MCSTR("list must be numeric"), nil);
354+
return;
355+
}
350356

351357
double t_minmax, t_cur_real;
352358
t_cur_real = MCNumberFetchAsReal((MCNumberRef)MCProperListFetchElementAtIndex(p_list, 0));

0 commit comments

Comments
 (0)