aboutsummaryrefslogtreecommitdiffstats
path: root/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'node.c')
-rw-r--r--node.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/node.c b/node.c
index a435e01d..2cd88331 100644
--- a/node.c
+++ b/node.c
@@ -59,7 +59,6 @@ r_force_number(NODE *n)
{
char *cp;
char *cpend;
- char save;
char *ptr;
extern double 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) {
@@ -941,13 +943,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) {