From e18ebe10166e2c63f3385666978b678fe6ce67a2 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 26 Jun 2016 18:26:39 +0300 Subject: Minor improvements after Andy's reworking of stuff. --- node.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'node.c') diff --git a/node.c b/node.c index bfa9a35f..39c25dfd 100644 --- a/node.c +++ b/node.c @@ -59,6 +59,7 @@ r_force_number(NODE *n) { char *cp; char *cpend; + char save; char *ptr; extern double strtod(); @@ -66,12 +67,12 @@ r_force_number(NODE *n) return n; /* - * we should always set NUMCUR and clear MAYBE_NUM, and we may possibly + * 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. */ - /* all the conditionals are an attempt to avoid the expensive strtod */ + /* All the conditionals are an attempt to avoid the expensive strtod */ n->flags |= NUMCUR; n->numbr = 0.0; @@ -122,23 +123,27 @@ r_force_number(NODE *n) goto badnum; } + errno = 0; if (do_non_decimal_data /* main.c assures false if do_posix */ && ! do_traditional && get_numbase(cp, true) != 10) { - errno = 0; + /* nondec2awknum() saves and restores the byte after the string itself */ n->numbr = nondec2awknum(cp, cpend - cp, &ptr); } else { - errno = 0; + save = *cpend; + *cpend = '\0'; n->numbr = (AWKNUM) strtod((const char *) cp, &ptr); + *cpend = save; } /* POSIX says trailing space is OK for NUMBER */ while (isspace((unsigned char) *ptr)) ptr++; + if (errno == 0) { if (ptr == cpend) goto goodnum; /* else keep the leading numeric value without updating flags */ - /* fall through to badnum*/ + /* fall through to badnum */ } else { errno = 0; /* @@ -151,7 +156,7 @@ r_force_number(NODE *n) * Or should we accept it as a NUMBER even though strtod * threw an error? */ - /* fall through to badnum*/ + /* fall through to badnum */ } badnum: n->flags &= ~MAYBE_NUM; -- cgit v1.2.3