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

Commit e8754ef

Browse files
Merge pull request #6811 from livecode/bugfix-21726
[[ Bug 21726 ]] Fix crash when using inf in math ops
2 parents baba06b + bc221ce commit e8754ef

File tree

5 files changed

+80
-11
lines changed

5 files changed

+80
-11
lines changed

docs/notes/bugfix-21726.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix crash when using "inf" in mathematical ops

engine/src/exec-math.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ void MCMathEvalMultiply(MCExecContext& ctxt, real64_t p_left, real64_t p_right,
590590
if (r_result == MCinfinity || MCS_geterrno() != 0)
591591
{
592592
MCS_seterrno(0);
593-
ctxt.LegacyThrow(EE_PLUS_RANGE);
593+
ctxt.LegacyThrow(EE_MULTIPLY_RANGE);
594594
return;
595595
}
596596
}

engine/src/operator.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ class MCMultiBinaryOperatorCtxt: public MCMultiBinaryOperator
171171
Eval(ctxt, t_left . double_value, t_right . double_value, r_value . double_value);
172172
}
173173

174-
if (ctxt . HasError())
175-
MCExecTypeRelease(r_value);
176-
else
174+
if (!ctxt . HasError())
175+
{
177176
r_value . type = t_left . type;
177+
}
178178

179179
if (t_left . type == kMCExecValueTypeArrayRef)
180180
MCValueRelease(t_left . arrayref_value);
@@ -243,12 +243,13 @@ class MCMultiBinaryCommutativeOperatorCtxt: public MCMultiBinaryOperator
243243
Eval(ctxt, t_left . double_value, t_right . double_value, r_value . double_value);
244244
}
245245

246-
if (ctxt . HasError())
247-
MCExecTypeRelease(r_value);
248-
else if (t_left . type == kMCExecValueTypeDouble && t_right . type == kMCExecValueTypeDouble)
249-
r_value . type = kMCExecValueTypeDouble;
250-
else
251-
r_value . type = kMCExecValueTypeArrayRef;
246+
if (!ctxt . HasError())
247+
{
248+
if (t_left . type == kMCExecValueTypeDouble && t_right . type == kMCExecValueTypeDouble)
249+
r_value . type = kMCExecValueTypeDouble;
250+
else
251+
r_value . type = kMCExecValueTypeArrayRef;
252+
}
252253

253254
if (t_left . type == kMCExecValueTypeArrayRef)
254255
MCValueRelease(t_left . valueref_value);

tests/_testlib.livecodescript

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ on TestAssertBroken pDescription, pExpectTrue, pReasonBroken
304304
_TestOutput pExpectTrue, pDescription, "TODO", pReasonBroken
305305
end TestAssertBroken
306306

307-
on TestAssertThrow pDescription, pHandler, pTarget, pErrorCodes, pParam
307+
function _TestHandlerThrows pHandler, pTarget, pErrorCodes, pParam
308308
local tError
309309
try
310310
dispatch pHandler to pTarget with pParam
@@ -319,10 +319,21 @@ on TestAssertThrow pDescription, pHandler, pTarget, pErrorCodes, pParam
319319
put tSuccess and __TestErrorMatches(tError, tErrorCode) into tSuccess
320320
delete the first line of tError
321321
end repeat
322+
return tSuccess
323+
end _TestHandlerThrows
322324

325+
on TestAssertThrow pDescription, pHandler, pTarget, pErrorCodes, pParam
326+
local tSuccess
327+
put _TestHandlerThrows(pHandler, pTarget, pErrorCodes, pParam) into tSuccess
323328
TestAssert pDescription, tSuccess
324329
end TestAssertThrow
325330

331+
on TestAssertBrokenThrow pDescription, pHandler, pReason, pTarget, pErrorCodes, pParam
332+
local tSuccess
333+
put _TestHandlerThrows(pHandler, pTarget, pErrorCodes, pParam) into tSuccess
334+
TestAssertBroken pDescription, tSuccess, pReason
335+
end TestAssertBrokenThrow
336+
326337
on TestAssertDoesNotThrow pDescription, pHandler, pTarget, pParam
327338
local tError
328339
try
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
script "CoreMathInfinity"
2+
/*
3+
Copyright (C) 2018 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
command _TestInfinityDivOperator
20+
get inf div 1 is inf
21+
end _TestInfinityDivOperator
22+
23+
on TestInfinityDivOperator
24+
TestAssertBrokenThrow "Infinity is unchanged by div operator", "_TestInfinityDivOperator", "Bug 14316", \
25+
the long id of me, "EE_DIV_RANGE"
26+
end TestInfinityDivOperator
27+
28+
on TestInfinitySubtractOperator
29+
TestAssert "Infinity is unchanged by subtract operator", inf - 1 is inf
30+
end TestInfinitySubtractOperator
31+
32+
on TestInfinityOverOperator
33+
TestAssert "Infinity is unchanged by over operator", inf / 2 is inf
34+
end TestInfinityOverOperator
35+
36+
on TestInfinityAddOperator
37+
TestAssert "Infinity is unchanged by add operator", inf + 1 is inf
38+
end TestInfinityAddOperator
39+
40+
command _TestInfinityMultiplyOperator
41+
get inf * 2 is inf
42+
end _TestInfinityMultiplyOperator
43+
44+
on TestInfinityMultiplyOperator
45+
TestAssertBrokenThrow "Infinity is unchanged by multiply operator", "_TestInfinityMultiplyOperator", "Bug 14316", \
46+
the long id of me, "EE_MULTIPLY_RANGE"
47+
end TestInfinityMultiplyOperator
48+
49+
command _TestInfinityPowerOperator
50+
get inf ^ 2 is inf
51+
end _TestInfinityPowerOperator
52+
53+
on TestInfinityPowerOperator
54+
TestAssertBrokenThrow "Infinity is unchanged by power operator", "_TestInfinityPowerOperator", "Bug 14316", \
55+
the long id of me, "EE_POW_RANGE"
56+
end TestInfinityPowerOperator

0 commit comments

Comments
 (0)