gawk-diffs
[Top][All Lists]
Advanced

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

[gawk-diffs] [SCM] gawk branch, feature/fixtype, updated. gawk-4.1.0-186


From: Andrew J. Schorr
Subject: [gawk-diffs] [SCM] gawk branch, feature/fixtype, updated. gawk-4.1.0-1866-g2ab2d5f
Date: Wed, 29 Jun 2016 18:26:07 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, feature/fixtype has been updated
       via  2ab2d5f2c468b647615d984cb7953217c63695af (commit)
      from  6e3f3560c1be80583b4045a627e483c572c895b3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=2ab2d5f2c468b647615d984cb7953217c63695af

commit 2ab2d5f2c468b647615d984cb7953217c63695af
Author: Andrew J. Schorr <address@hidden>
Date:   Wed Jun 29 14:25:31 2016 -0400

    Optimize r_force_number and fix obscure bug in get_ieee_magic_val.

diff --git a/ChangeLog b/ChangeLog
index 16f7f18..d78e0b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-06-29         Andrew J. Schorr     <address@hidden>
+
+       * node.c (r_force_number): Optimize by trimming leading and trailing
+       white space before we inspect the string contents.
+       (get_ieee_magic_val): Must terminate the string with '\0' before
+       calling strtod.
+
 2016-06-27         Andrew J. Schorr     <address@hidden>
 
        * gawkapi.h (awk_string): Add comment about the potential lack of
diff --git a/node.c b/node.c
index 2c099bd..41dcb2f 100644
--- a/node.c
+++ b/node.c
@@ -30,7 +30,7 @@
 
 static int is_ieee_magic_val(const char *val);
 static NODE *r_make_number(double x);
-static AWKNUM get_ieee_magic_val(const char *val);
+static AWKNUM get_ieee_magic_val(char *val);
 extern NODE **fmt_list;          /* declared in eval.c */
 
 NODE *(*make_number)(double) = r_make_number;
@@ -77,10 +77,21 @@ r_force_number(NODE *n)
        n->flags |= NUMCUR;
        n->numbr = 0.0;
 
-       if (n->stlen == 0)
-               goto badnum;
-
+       /* Trim leading white space, bailing out if there's nothing else */
        cp = n->stptr;
+       cpend = cp + n->stlen;
+       while (1) {
+               if (cp == cpend)
+                       goto badnum;
+               if (!isspace((unsigned char) *cp))
+                       break;
+               cp++;
+       }
+       /* At this point, we know the string is not entirely white space */
+       /* Trim trailing white space */
+       while (isspace((unsigned char) cpend[-1]))
+               cpend--;
+
        /*
         * 2/2007:
         * POSIX, by way of severe language lawyering, seems to
@@ -91,8 +102,8 @@ r_force_number(NODE *n)
        if (! do_posix) {
                if (is_alpha((unsigned char) *cp))
                        goto badnum;
-               else if (n->stlen == 4 && is_ieee_magic_val(n->stptr)) {
-                       n->numbr = get_ieee_magic_val(n->stptr);
+               else if (cpend == cp+4 && is_ieee_magic_val(cp)) {
+                       n->numbr = get_ieee_magic_val(cp);
                        goto goodnum;
                }
                /* else
@@ -101,12 +112,7 @@ r_force_number(NODE *n)
        /* else POSIX, so
                fall through */
 
-       cpend = cp + n->stlen;
-       while (cp < cpend && isspace((unsigned char) *cp))
-               cp++;
-
-       if (   cp == cpend              /* only spaces, or */
-           || (! do_posix              /* not POSIXLY paranoid and */
+       if (   (! do_posix              /* not POSIXLY paranoid and */
                && (is_alpha((unsigned char) *cp)       /* letter, or */
                                        /* CANNOT do non-decimal and saw 0x */
                    || (! do_non_decimal_data && is_hex(cp))))) {
@@ -116,7 +122,7 @@ r_force_number(NODE *n)
        if (cpend - cp == 1) {          /* only one character */
                if (isdigit((unsigned char) *cp)) {     /* it's a digit! */
                        n->numbr = (AWKNUM)(*cp - '0');
-                       if (cp == n->stptr)             /* no leading spaces */
+                       if (n->stlen == 1)              /* no white space */
                                n->flags |= NUMINT;
                        goto goodnum;
                }
@@ -135,10 +141,6 @@ r_force_number(NODE *n)
                *cpend = save;
        }
 
-       /* POSIX says trailing space is OK for NUMBER */
-       while (ptr < cpend && isspace((unsigned char) *ptr))
-               ptr++;
-
        if (errno == 0) {
                if (ptr == cpend)
                        goto goodnum;
@@ -937,14 +939,18 @@ is_ieee_magic_val(const char *val)
 /* get_ieee_magic_val --- return magic value for string */
 
 static AWKNUM
-get_ieee_magic_val(const char *val)
+get_ieee_magic_val(char *val)
 {
        static bool first = true;
        static AWKNUM inf;
        static AWKNUM nan;
+       char save;
 
        char *ptr;
+       save = val[4];
+       val[4] = '\0';
        AWKNUM v = strtod(val, &ptr);
+       val[4] = save;
 
        if (val == ptr) { /* Older strtod implementations don't support inf or 
nan. */
                if (first) {

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog |    7 +++++++
 node.c    |   42 ++++++++++++++++++++++++------------------
 2 files changed, 31 insertions(+), 18 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]