aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/builtin.c b/builtin.c
index 77cf3fc5..032f0ec7 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2035,16 +2035,12 @@ do_mktime(int nargs)
int month, day, hour, minute, second, count;
int dst = -1; /* default is unknown */
time_t then_stamp;
- char save;
t1 = POP_SCALAR();
if (do_lint && (fixtype(t1)->flags & STRING) == 0)
lintwarn(_("mktime: received non-string argument"));
t1 = force_string(t1);
- save = t1->stptr[t1->stlen];
- t1->stptr[t1->stlen] = '\0';
-
count = sscanf(t1->stptr, "%ld %d %d %d %d %d %d",
& year, & month, & day,
& hour, & minute, & second,
@@ -2058,7 +2054,6 @@ do_mktime(int nargs)
|| (month < 1 || month > 12) ))
lintwarn(_("mktime: at least one of the values is out of the default range"));
- t1->stptr[t1->stlen] = save;
DEREF(t1);
if (count < 6
@@ -2088,7 +2083,6 @@ do_system(int nargs)
NODE *tmp;
AWKNUM ret = 0; /* floating point on purpose, compat Unix awk */
char *cmd;
- char save;
int status;
if (do_sandbox)
@@ -2101,10 +2095,6 @@ do_system(int nargs)
cmd = force_string(tmp)->stptr;
if (cmd && *cmd) {
- /* insure arg to system is zero-terminated */
- save = cmd[tmp->stlen];
- cmd[tmp->stlen] = '\0';
-
os_restore_mode(fileno(stdin));
#ifdef SIGPIPE
signal(SIGPIPE, SIG_DFL);
@@ -2148,7 +2138,6 @@ do_system(int nargs)
signal(SIGPIPE, SIG_IGN);
#endif
- cmd[tmp->stlen] = save;
}
DEREF(tmp);
return make_number((AWKNUM) ret);
@@ -2200,13 +2189,7 @@ do_print(int nargs, int redirtype)
DEREF(args_array[i]);
fatal(_("attempt to use array `%s' in a scalar context"), array_vname(tmp));
}
-
- if (tmp->type == Node_typedregex)
- args_array[i] = force_string(tmp);
- else if ( (tmp->flags & STRCUR) == 0
- || ( tmp->stfmt != STFMT_UNUSED
- && tmp->stfmt != OFMTidx))
- args_array[i] = format_val(OFMT, OFMTidx, tmp);
+ args_array[i] = force_string_ofmt(tmp);
}
if (redir_exp != NULL) {
@@ -3638,6 +3621,11 @@ nondec2awknum(char *str, size_t len, char **endptr)
*endptr = str;
} else {
decimal:
+ /*
+ * Terminating is probably unnecessary, since the caller always
+ * passes a string ending with '\0' or white space, but it
+ * seems safest to leave this to avoid future problems.
+ */
save = str[len];
str[len] = '\0';
retval = strtod(str, endptr);
@@ -3963,14 +3951,14 @@ do_typeof(int nargs)
break;
case Node_val:
case Node_var:
- switch (arg->flags & (STRING|NUMBER|MAYBE_NUM)) {
+ switch (fixtype(arg)->flags & (STRING|NUMBER|MAYBE_NUM)) {
case STRING:
res = "string";
break;
case NUMBER:
res = "number";
break;
- case STRING|MAYBE_NUM:
+ case NUMBER|MAYBE_NUM:
res = "strnum";
break;
case NUMBER|STRING: