diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2019-01-25 12:56:06 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2019-01-25 12:56:06 +0200 |
commit | 9dbd1f1de31ea9a805d1095f5586fb146a1b6a9e (patch) | |
tree | c031f1d8f5995833fc6e069d252cb313e532b791 | |
parent | c3c7c1370e9a9969bdcaf2018c5e62096ac15c55 (diff) | |
download | one-true-awk-9dbd1f1de31ea9a805d1095f5586fb146a1b6a9e.tar.gz |
Make getline POSIX compliant w.r.t. numeric strings.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bugs-fixed/README | 5 | ||||
-rw-r--r-- | bugs-fixed/getline-numeric.awk | 6 | ||||
-rw-r--r-- | bugs-fixed/getline-numeric.bad | 6 | ||||
-rw-r--r-- | bugs-fixed/getline-numeric.in | 2 | ||||
-rw-r--r-- | bugs-fixed/getline-numeric.ok | 6 | ||||
-rw-r--r-- | run.c | 8 |
7 files changed, 37 insertions, 1 deletions
@@ -1,3 +1,8 @@ +2019-01-25 Arnold D. Robbins <arnold@skeeve.com> + + * run.c (awkgetline): Check for numeric value in all getline + variants. See the numeric-getline.* files in bugs-fixed directory. + 2018-08-29 Arnold D. Robbins <arnold@skeeve.com> * REGRESS: Check for existence of a.out. If not there, run diff --git a/bugs-fixed/README b/bugs-fixed/README index 9c644f9..2f27c10 100644 --- a/bugs-fixed/README +++ b/bugs-fixed/README @@ -51,4 +51,7 @@ array passed as the second argument, then split() would previously read from the freed memory and possibly produce incorrect results (depending on the system's malloc()/free() behaviour.) - +15. getline-numeric: The `getline xx < file' syntax did not check if +values were numeric, in discordance from POSIX. Test case adapted from +one posted by Ben Bacarisse <ben.usenet@bsb.me.uk> in comp.lang.awk, +January 2019. diff --git a/bugs-fixed/getline-numeric.awk b/bugs-fixed/getline-numeric.awk new file mode 100644 index 0000000..5571a95 --- /dev/null +++ b/bugs-fixed/getline-numeric.awk @@ -0,0 +1,6 @@ +{ + print $0, ($0 <= 50 ? "<=" : ">"), 50 + getline dd < ARGV[1] + print dd, (dd <= 50 ? "<=" : ">"), 50 + if (dd == $0) print "same" +} diff --git a/bugs-fixed/getline-numeric.bad b/bugs-fixed/getline-numeric.bad new file mode 100644 index 0000000..5247bfc --- /dev/null +++ b/bugs-fixed/getline-numeric.bad @@ -0,0 +1,6 @@ +120 > 50 +120 <= 50 +same +120 > 50 +120 <= 50 +same diff --git a/bugs-fixed/getline-numeric.in b/bugs-fixed/getline-numeric.in new file mode 100644 index 0000000..b635013 --- /dev/null +++ b/bugs-fixed/getline-numeric.in @@ -0,0 +1,2 @@ +120 +120 diff --git a/bugs-fixed/getline-numeric.ok b/bugs-fixed/getline-numeric.ok new file mode 100644 index 0000000..901a4d9 --- /dev/null +++ b/bugs-fixed/getline-numeric.ok @@ -0,0 +1,6 @@ +120 > 50 +120 > 50 +same +120 > 50 +120 > 50 +same @@ -425,6 +425,10 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ } else if (a[0] != NULL) { /* getline var <file */ x = execute(a[0]); setsval(x, buf); + if (is_number(x->sval)) { + x->fval = atof(x->sval); + x->tval |= NUM; + } tempfree(x); } else { /* getline <file */ setsval(fldtab[0], buf); @@ -440,6 +444,10 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ n = getrec(&buf, &bufsize, 0); x = execute(a[0]); setsval(x, buf); + if (is_number(x->sval)) { + x->fval = atof(x->sval); + x->tval |= NUM; + } tempfree(x); } } |