aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2019-07-23 06:06:41 +0300
committerArnold D. Robbins <arnold@skeeve.com>2019-07-23 06:06:41 +0300
commit3940fe507bc67794100e1f075597f451ef1f3c22 (patch)
tree4fbca9ff8980d0a598d1112a8702b1dc80ed9064 /builtin.c
parent2a7b1a82bccd03781452124dff9194ab308a83fb (diff)
downloadegawk-3940fe507bc67794100e1f075597f451ef1f3c22.tar.gz
egawk-3940fe507bc67794100e1f075597f451ef1f3c22.tar.bz2
egawk-3940fe507bc67794100e1f075597f451ef1f3c22.zip
Fix checking for negative arguments to bitwise functions.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/builtin.c b/builtin.c
index bea88b86..2f379689 100644
--- a/builtin.c
+++ b/builtin.c
@@ -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)