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
if cell^.ContentType = cctNumber then
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))
else
Result := FloatResult(cell^.NumberValue);
@ -3240,11 +3243,14 @@ begin
Result := ErrorResult(errWrongType);
end else
if (cell^.ContentType = cctNumber) or (cell^.ContentType = cctDateTime) then
begin
if frac(cell^.NumberValue) = 0.0 then
begin
if (frac(cell^.NumberValue) = 0.0) and
(cell^.NumberValue >= -Integer(MaxInt)-1) and
(cell^.NumberValue <= MaxInt)
then
Result := IntegerResult(-trunc(cell^.NumberValue))
else
Result := FloatResult(cell^.NumberValue);
else
Result := FloatResult(-cell^.NumberValue);
end else
if (cell^.ContentType = cctBool) then
Result := ErrorResult(errWrongType);