Skip to content
Tcl Source Code View Ticket
Login

View Ticket

expr parser and "nan()"

Closed / Fixed3402540fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2011-09-01 15:40:39
% expr {nan()}
missing operator at _@_
in expression "...es.
#
# Copyright (c) _@_"

Something's way off here, sending us
where we shouldn't be going.
ferrieuxplain2011-09-01 22:52:08
Also broken in 8.6 trunk and *not* fixed by the bug-3401704 patch.
ferrieuxplain2011-09-01 22:58:37
It goes astray because in sNANPAREN the case of en empty argument is not checked, hence the closing paren is taken as an hex digit, and the final \0 continues into the state machine...
Will fix by adding an "else" in sNANPAREN.
dgpplain2011-09-01 23:03:51
elated bugs:

% string is double nan(1,2,3,4,5)
1
% string is double nan(
1

Patch on the way.
ferrieuxplain2011-09-01 23:05:36
--- generic/tclStrToD.c
+++ generic/tclStrToD.c
@@ -1099,10 +1099,14 @@
                    d = c - '0';
                } else if (c >= 'a' && c <= 'f') {
                    d = 10 + c - 'a';
                } else if (c >= 'A' && c <= 'F') {
                    d = 10 + c - 'A';
+               } else {
+                   /* Nan(NotHex) or Nan() => we stop at Nan */
+                   /* acceptPoint and acceptLen have been set in sNAN */
+                   goto endgame;
                }
                significandWide = (significandWide << 4) + d;
                state = sNANHEX;
                break;
            }
ferrieuxplain2011-09-01 23:07:06
sorry, xed. This patch fixes it by parsing Nan() and Nan(nonhex) as "Nan"+"(...)".
Is it okay ?
dgpplain2011-09-01 23:07:19
Yes, that plus adding the missing increment
on numSigDigs.  Will commit after adding tests
as well.
dgpplain2011-09-02 01:27:59
allow_comments - 1
Log in (anonymous is fine) to add a comment.