diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-07-08 15:26:00 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-07-08 15:26:00 -0400 |
commit | c86137f472fdf876c2c223c8d99f673f477b7554 (patch) | |
tree | 7ed0e172eaa8d4f831a2d59287547f63f1e71dee /node.c | |
parent | 4a0f74139fb702a14c2e6782fb1965245e4f9d2f (diff) | |
download | egawk-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.c | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -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) { |