aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--builtin.c4
-rw-r--r--eval.c5
-rw-r--r--io.c2
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am4
-rw-r--r--test/strnum2.awk10
-rw-r--r--test/strnum2.ok2
8 files changed, 35 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 796dc9cf..2d0ca882 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-06-20 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * builtin.c (do_strftime): Call fixtype before checking flags for
+ STRING type.
+ (do_print): Call fixtype before checking whether argument is a NUMBER.
+ * eval.c (set_BINMODE): Call fixtype before checking value type.
+ No need to call force_number if the flags say it's a number.
+ (r_get_field): Fix lint check for non-numeric argument.
+ * io.c (redirect): Call fixtype before checking whether it's a string.
+
2016-06-18 Andrew J. Schorr <aschorr@telemetry-investments.com>
* node.c (r_force_number): Fix typo in comment.
diff --git a/builtin.c b/builtin.c
index 7ef5d3a1..67b963e7 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1915,7 +1915,7 @@ do_strftime(int nargs)
unref(sub);
if (val != NULL) {
- if (do_lint && (val->flags & STRING) == 0)
+ if (do_lint && (fixtype(val)->flags & STRING) == 0)
lintwarn(_("strftime: format value in PROCINFO[\"strftime\"] has numeric type"));
val = force_string(val);
format = val->stptr;
@@ -2197,7 +2197,7 @@ do_print(int nargs, int redirtype)
if (tmp->type == Node_typedregex)
args_array[i] = force_string(tmp);
- else if ((tmp->flags & (NUMBER|STRING)) == NUMBER) {
+ else if ((fixtype(tmp)->flags & (NUMBER|STRING)) == NUMBER) {
if (OFMTidx == CONVFMTidx)
args_array[i] = force_string(tmp);
else
diff --git a/eval.c b/eval.c
index ee674911..d7735205 100644
--- a/eval.c
+++ b/eval.c
@@ -712,7 +712,7 @@ set_BINMODE()
{
static bool warned = false;
char *p;
- NODE *v = BINMODE_node->var_value;
+ NODE *v = fixtype(BINMODE_node->var_value);
if ((do_lint || do_traditional) && ! warned) {
warned = true;
@@ -721,7 +721,6 @@ set_BINMODE()
if (do_traditional)
BINMODE = TEXT_TRANSLATE;
else if ((v->flags & NUMBER) != 0) {
- (void) force_number(v);
BINMODE = get_number_si(v);
/* Make sure the value is rational. */
if (BINMODE < TEXT_TRANSLATE)
@@ -1157,7 +1156,7 @@ r_get_field(NODE *n, Func_ptr *assign, bool reference)
if (assign)
*assign = NULL;
if (do_lint) {
- if ((n->flags & NUMBER) == 0) {
+ if ((fixtype(n)->flags & NUMBER) == 0) {
lintwarn(_("attempt to field reference from non-numeric value"));
if (n->stlen == 0)
lintwarn(_("attempt to field reference from null string"));
diff --git a/io.c b/io.c
index 94a5dfc3..b9bce694 100644
--- a/io.c
+++ b/io.c
@@ -1083,7 +1083,7 @@ redirect_string(const char *str, size_t explen, bool not_string,
struct redirect *
redirect(NODE *redir_exp, int redirtype, int *errflg, bool failure_fatal)
{
- bool not_string = ((redir_exp->flags & STRING) == 0);
+ bool not_string = ((fixtype(redir_exp)->flags & STRING) == 0);
redir_exp = force_string(redir_exp);
return redirect_string(redir_exp->stptr, redir_exp->stlen, not_string,
diff --git a/test/ChangeLog b/test/ChangeLog
index e667de55..5a575841 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2016-06-20 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * Makefile.am (strnum2): New test.
+ * strnum2.awk, strnum2.ok: New files.
+
2016-06-14 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (subback): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 6c893cce..499107c5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -999,6 +999,8 @@ EXTRA_DIST = \
strftlng.ok \
strnum1.awk \
strnum1.ok \
+ strnum2.awk \
+ strnum2.ok \
strtod.awk \
strtod.in \
strtod.ok \
@@ -1165,7 +1167,7 @@ BASIC_TESTS = \
reparse resplit rri1 rs rscompat rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite \
scalar sclforin sclifin sigpipe1 sortempty sortglos splitargv splitarr splitdef \
- splitvar splitwht strcat1 strnum1 strtod subamp subback subi18n \
+ splitvar splitwht strcat1 strnum1 strnum2 strtod subamp subback subi18n \
subsepnm subslash substr swaplns synerr1 synerr2 tradanch tweakfld \
uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs \
wideidx wideidx2 widesub widesub2 widesub3 widesub4 wjposer1 \
diff --git a/test/strnum2.awk b/test/strnum2.awk
new file mode 100644
index 00000000..16e6f5d0
--- /dev/null
+++ b/test/strnum2.awk
@@ -0,0 +1,10 @@
+BEGIN {
+ split("1.234", f)
+ OFMT = "%.1f"
+ # check whether strnum is displayed the same way before and
+ # after force_number is called. Also, should numeric strings
+ # be formatted with OFMT or show the original string value?
+ print f[1]
+ x = f[1]+0 # trigger conversion to NUMBER
+ print f[1]
+}
diff --git a/test/strnum2.ok b/test/strnum2.ok
new file mode 100644
index 00000000..f5103ca9
--- /dev/null
+++ b/test/strnum2.ok
@@ -0,0 +1,2 @@
+1.2
+1.2