Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/historical/nawk/dist Don't try so hard to convert s...



details:   https://anonhg.NetBSD.org/src/rev/a95c7545569f
branches:  trunk
changeset: 943362:a95c7545569f
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Aug 31 23:36:58 2020 +0000

description:
Don't try so hard to convert strings into numbers. Results in bogus
conversions like:

% awk 'BEGIN { print "nanotime" + 123 }'
nan
% awk 'BEGIN { print "microtime" + 123 }'
123
% awk 'BEGIN { print "inftime" + 123 }'
inf

diffstat:

 external/historical/nawk/dist/tran.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (18 lines):

diff -r cc21e69932fd -r a95c7545569f external/historical/nawk/dist/tran.c
--- a/external/historical/nawk/dist/tran.c      Mon Aug 31 20:34:43 2020 +0000
+++ b/external/historical/nawk/dist/tran.c      Mon Aug 31 23:36:58 2020 +0000
@@ -404,9 +404,12 @@
        else if (isrec(vp) && !donerec)
                recbld();
        if (!isnum(vp)) {       /* not a number */
-               vp->fval = atof(vp->sval);      /* best guess */
-               if (is_number(vp->sval) && !(vp->tval&CON))
+               if (is_number(vp->sval) && !(vp->tval&CON)) {
+                       vp->fval = atof(vp->sval);      /* best guess */
                        vp->tval |= NUM;        /* make NUM only sparingly */
+               } else {
+                       vp->fval = 0;
+               }
        }
           dprintf( ("getfval %p: %s = %g, t=%o\n",
                (void*)vp, NN(vp->nval), vp->fval, vp->tval) );



Home | Main Index | Thread Index | Old Index