fpspreadsheet: Fix integer overflow in formulas with large integer values.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8246 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-04-08 17:01:55 +00:00
parent 0f64e793db
commit 520e94f2d7

View File

@@ -3181,7 +3181,10 @@ begin
else else
if cell^.ContentType = cctNumber then if cell^.ContentType = cctNumber then
begin begin
if frac(cell^.NumberValue) = 0.0 then if (frac(cell^.NumberValue) = 0.0) and
(cell^.Numbervalue >= -Integer(MaxInt)-1) and
(cell^.NumberValue <= MaxInt)
then
Result := IntegerResult(trunc(cell^.NumberValue)) Result := IntegerResult(trunc(cell^.NumberValue))
else else
Result := FloatResult(cell^.NumberValue); Result := FloatResult(cell^.NumberValue);
@@ -3241,10 +3244,13 @@ begin
end else end else
if (cell^.ContentType = cctNumber) or (cell^.ContentType = cctDateTime) then if (cell^.ContentType = cctNumber) or (cell^.ContentType = cctDateTime) then
begin begin
if frac(cell^.NumberValue) = 0.0 then if (frac(cell^.NumberValue) = 0.0) and
(cell^.NumberValue >= -Integer(MaxInt)-1) and
(cell^.NumberValue <= MaxInt)
then
Result := IntegerResult(-trunc(cell^.NumberValue)) Result := IntegerResult(-trunc(cell^.NumberValue))
else else
Result := FloatResult(cell^.NumberValue); Result := FloatResult(-cell^.NumberValue);
end else end else
if (cell^.ContentType = cctBool) then if (cell^.ContentType = cctBool) then
Result := ErrorResult(errWrongType); Result := ErrorResult(errWrongType);