diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2019-07-23 06:06:41 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2019-07-23 06:06:41 +0300 |
commit | 3940fe507bc67794100e1f075597f451ef1f3c22 (patch) | |
tree | 4fbca9ff8980d0a598d1112a8702b1dc80ed9064 | |
parent | 2a7b1a82bccd03781452124dff9194ab308a83fb (diff) | |
download | egawk-3940fe507bc67794100e1f075597f451ef1f3c22.tar.gz egawk-3940fe507bc67794100e1f075597f451ef1f3c22.tar.bz2 egawk-3940fe507bc67794100e1f075597f451ef1f3c22.zip |
Fix checking for negative arguments to bitwise functions.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | builtin.c | 18 |
2 files changed, 20 insertions, 10 deletions
@@ -1,3 +1,14 @@ +2019-07-23 Andrew J. Schorr <aschorr@telemetry-investments.com> + + Fix reporting of negative arguments for and(), or() and xor(). + Thanks to Koichi Murase <myoga.murase@gmail.com> for the + report. + + * builtin.c (do_and): Use nargs instead of i in the loop to + check for non-numeric and negative arguments. + (do_or): Ditto. + (do_xor): Ditto. + 2019-07-23 Arnold D. Robbins <arnold@skeeve.com> * Checklist: Updated. @@ -23,6 +34,7 @@ * gawkapi.h: Update copyright year, fix some spelling errors. 2019-07-08 Andrew J. Schorr <aschorr@telemetry-investments.com> +2019-07-08 Andrew J. Schorr <aschorr@telemetry-investments.com> * gawkapi.h (gawk_api_major_version): Bump from 2 to 3 because the namespace changes altered the function signatures in gawk_api_t. @@ -3467,20 +3467,19 @@ do_and(int nargs) NODE *s1; uintmax_t res, uval; AWKNUM val; - int i; res = ~0; /* start off with all ones */ if (nargs < 2) fatal(_("and: called with less than two arguments")); - for (i = 1; nargs > 0; nargs--, i++) { + for (; nargs > 0; nargs--) { s1 = POP_SCALAR(); if (do_lint && (fixtype(s1)->flags & NUMBER) == 0) - lintwarn(_("and: argument %d is non-numeric"), i); + lintwarn(_("and: argument %d is non-numeric"), nargs); val = force_number(s1)->numbr; if (val < 0) - fatal(_("and: argument %d negative value %g is not allowed"), i, val); + fatal(_("and: argument %d negative value %g is not allowed"), nargs, val); uval = (uintmax_t) val; res &= uval; @@ -3499,20 +3498,19 @@ do_or(int nargs) NODE *s1; uintmax_t res, uval; AWKNUM val; - int i; res = 0; if (nargs < 2) fatal(_("or: called with less than two arguments")); - for (i = 1; nargs > 0; nargs--, i++) { + for (; nargs > 0; nargs--) { s1 = POP_SCALAR(); if (do_lint && (fixtype(s1)->flags & NUMBER) == 0) - lintwarn(_("or: argument %d is non-numeric"), i); + lintwarn(_("or: argument %d is non-numeric"), nargs); val = force_number(s1)->numbr; if (val < 0) - fatal(_("or: argument %d negative value %g is not allowed"), i, val); + fatal(_("or: argument %d negative value %g is not allowed"), nargs, val); uval = (uintmax_t) val; res |= uval; @@ -3540,11 +3538,11 @@ do_xor(int nargs) for (i = 1; nargs > 0; nargs--, i++) { s1 = POP_SCALAR(); if (do_lint && (fixtype(s1)->flags & NUMBER) == 0) - lintwarn(_("xor: argument %d is non-numeric"), i); + lintwarn(_("xor: argument %d is non-numeric"), nargs); val = force_number(s1)->numbr; if (val < 0) - fatal(_("xor: argument %d negative value %g is not allowed"), i, val); + fatal(_("xor: argument %d negative value %g is not allowed"), nargs, val); uval = (uintmax_t) val; if (i == 1) |