diff options
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -59,7 +59,6 @@ r_force_number(NODE *n) { char *cp; char *cpend; - char save; char *ptr; extern double strtod(); @@ -67,9 +66,9 @@ r_force_number(NODE *n) return n; /* - * We should always set NUMCUR and clear MAYBE_NUM, and we may possibly - * change STRING to NUMBER if MAYBE_NUM was set and it's a good numeric - * string. + * We should always set NUMCUR. If MAYBE_NUM is set and it's a + * numeric string, we clear STRING and enable NUMBER, but if it's not + * numeric, we disable MAYBE_NUM. */ /* All the conditionals are an attempt to avoid the expensive strtod */ @@ -133,10 +132,13 @@ r_force_number(NODE *n) /* nondec2awknum() saves and restores the byte after the string itself */ n->numbr = nondec2awknum(cp, cpend - cp, &ptr); } else { - save = *cpend; - *cpend = '\0'; + /* + * There is no need to set *cpend to '\0' because it is either + * pointing to white space or the '\0' at the end of the string. + * In either case, strtod should terminate on that character + * or earlier due to non-numeric characters. + */ n->numbr = (AWKNUM) strtod((const char *) cp, &ptr); - *cpend = save; } if (errno == 0) { @@ -164,7 +166,8 @@ badnum: goodnum: if ((n->flags & MAYBE_NUM) != 0) { - n->flags &= ~(MAYBE_NUM|STRING); + /* leave MAYBE_NUM enabled to indicate that this is a strnum */ + n->flags &= ~STRING; n->flags |= NUMBER; } return n; @@ -300,7 +303,6 @@ r_dupnode(NODE *n) getnode(r); *r = *n; - r->flags &= ~FIELD; r->flags |= MALLOC; r->valref = 1; /* @@ -942,13 +944,14 @@ 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'; + /* + * There is no need to set val[4] to '\0' because it is either white + * space or the NUL character at the end of the string. Either way, + * strtod should terminate on that character. + */ AWKNUM v = strtod(val, &ptr); - val[4] = save; if (val == ptr) { /* Older strtod implementations don't support inf or nan. */ if (first) { |