Skip to content
Tcl Source Code View Ticket
Login

View Ticket

number parser fails handling int overflow in exponents

Closed / Fixed1de6b0629e6b52afee3c3a763b02d9de6a39d780Created 7 years agoUpdated 7 years ago
Descriptionplain2019-12-20 14:18:26
% expr 1e2147483647
Inf
% expr 1e2147483648
0.0

% expr 10e2147483647
0.0

Sure there are more cases to illustrate...

Issue is the "exponent" argument of Make(Low|High)PrecisionDouble() has type int, but longs are being passed without care to deal with overflow.
Referenced by4
  • fa8169ab74Merge Tcl 8.7 changes to deal with integer overflow in the exponent, and floating point overflow in the significand, of floating point input conversion (Bug [1de6b0629e] check-in2019-12-27 00:34:51
  • 5cb42f70adMerge Tcl 8.6 changes to deal with integer overflow in the exponent, and floating point overflow in the significand, of floating point input conversion (Bug [1de6b0629e] check-in2019-12-27 00:23:49
  • b64a60bb4fMerge Tcl 8.5 changes to deal with integer overflow in the exponent, and floating point overflow in the significand, of floating point input conversion (Bug [1de6b0629e] check-in2019-12-27 00:12:58
  • c3d4779949Merge changes to deal with integer overflow in the exponent, and floating point overflow in the significand, of floating point input conversion (Bug [1de6b0629e] check-in2019-12-27 00:03:41
dgpplain2019-12-22 18:10:50
See committed tests for more similar to the original.

These are different

% expr 0e309
0.0
% expr 0e310
Inf
dgpplain2019-12-23 16:00:47
Still more....

% expr 1[string repeat 0 324]1e-250
1e+75
% expr 1[string repeat 0 325]1e-250
domain error: argument not in valid range
dgpplain2019-12-23 16:15:17
The last comment appears to demonstrate something going wrong with RefineApproximation(). This is getting beyond simple fixes. Calling in
the author.
kbkwiki2019-12-24 14:50:25

We shouldn't be even getting into RefineApproximation in that case.

I hypothesize that it's getting an integer overflow in the quick checks in MakeHighPrecisionDouble but I won't be able to look in more detail for a few days.

kbkwiki2019-12-24 17:34:01

We shouldn't be even getting into RefineApproximation in that case.

I hypothesize that it's getting an integer overflow in the quick checks in MakeHighPrecisionDouble but I won't be able to look in more detail for a few days.

kbkplain2019-12-26 23:59:31
Putative fix committed to the branch. Merging and running tests on the cascade of 8.5->8.6->8.7->trunk now and will commit as they succeed.
kbkplain2019-12-27 00:37:48
All the test cases in the bug report pass now. Merged changes forward to core-8-5-branch, core-8-6-branch, core-8-branch, and trunk.
fvogelplain2020-01-02 11:37:42
Since this fix, the build is now failing with MSVC as follows:

tclStrToD.c
C:\Users\francois\Documents\Development\tcltk-fossil\tcl\win\..\generic\tclStrToD.c(1585) : error C2220: warning treated as error - no 'object' file generated
C:\Users\francois\Documents\Development\tcltk-fossil\tcl\win\..\generic\tclStrToD.c(1585) : warning C4013: 'copysign' undefined; assuming extern returning int
kbkwiki2020-01-02 16:44:21

@fvogel:

(1) Is this a MSVC6 compilation? Recent MSVC's (at least since VS2013) are documented to have copysign.

(2) Does it work to include the following code burst near the top of tclStrToD.c (somewhere after the #includes)?

#if defined(_MSC_VER_)
inline static double
copysign(double a, double b) {
    return _copysign(a, b);
}
#endif

If it works, could you commit that change and re-close the bug?

fvogelplain2020-01-02 21:04:42
@kbk: many thanks for the replacement.

1. No, it's a MSVC Express 2008 compiler.

2. Yes it does. I have slightly improved the test to define the replacement function only for MSVC compilers before Visual Studio 2013 since you said VS2013 has it.

Committed now.

Many thanks!
fvogel Closed ticket [1de6b0629e]. [History diff]2020-01-02 21:04:50
Log in (anonymous is fine) to add a comment.