aboutsummaryrefslogtreecommitdiffstats
path: root/node.c
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2016-07-08 15:26:00 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2016-07-08 15:26:00 -0400
commitc86137f472fdf876c2c223c8d99f673f477b7554 (patch)
tree7ed0e172eaa8d4f831a2d59287547f63f1e71dee /node.c
parent4a0f74139fb702a14c2e6782fb1965245e4f9d2f (diff)
downloadegawk-c86137f472fdf876c2c223c8d99f673f477b7554.tar.gz
egawk-c86137f472fdf876c2c223c8d99f673f477b7554.tar.bz2
egawk-c86137f472fdf876c2c223c8d99f673f477b7554.zip
Optimization: support unterminated field strings inside gawk, but make terminated copies for the API.
Diffstat (limited to 'node.c')
-rw-r--r--node.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/node.c b/node.c
index 37aa9463..f40ccdc9 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();
@@ -132,13 +133,10 @@ r_force_number(NODE *n)
/* nondec2awknum() saves and restores the byte after the string itself */
n->numbr = nondec2awknum(cp, cpend - cp, &ptr);
} else {
- /*
- * 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.
- */
+ save = *cpend;
+ *cpend = '\0';
n->numbr = (AWKNUM) strtod((const char *) cp, &ptr);
+ *cpend = save;
}
if (errno == 0) {
@@ -944,14 +942,13 @@ get_ieee_magic_val(char *val)
static bool first = true;
static AWKNUM inf;
static AWKNUM nan;
+ char save;
char *ptr;
- /*
- * 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.
- */
+ 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) {