summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2019-07-23 06:11:43 +0300
committerArnold D. Robbins <arnold@skeeve.com>2019-07-23 06:11:43 +0300
commit9a80874f7f13422d2e60cac2bfa87469dfa25152 (patch)
treeaaa146d003677a643b8a3d66ed0a4af500bf1727
parent3940fe507bc67794100e1f075597f451ef1f3c22 (diff)
downloadgawk-9a80874f7f13422d2e60cac2bfa87469dfa25152.tar.gz
Further improvements to bitwise functions.
-rw-r--r--ChangeLog6
-rw-r--r--builtin.c12
2 files changed, 10 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 6ba53f64..5a20c09b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-23 Koichi Murase <myoga.murase@gmail.com>
+
+ * builtin.c (do_xor): Remove unneeded local variable `i'. Simplify
+ the loop's computation.
+ (do_and): Improve the initial value for the result.
+
2019-07-23 Andrew J. Schorr <aschorr@telemetry-investments.com>
Fix reporting of negative arguments for and(), or() and xor().
diff --git a/builtin.c b/builtin.c
index 2f379689..1c205aa4 100644
--- a/builtin.c
+++ b/builtin.c
@@ -3468,7 +3468,7 @@ do_and(int nargs)
uintmax_t res, uval;
AWKNUM val;
- res = ~0; /* start off with all ones */
+ res = ~(uintmax_t) 0; /* start off with all ones */
if (nargs < 2)
fatal(_("and: called with less than two arguments"));
@@ -3529,13 +3529,12 @@ do_xor(int nargs)
NODE *s1;
uintmax_t res, uval;
AWKNUM val;
- int i;
if (nargs < 2)
fatal(_("xor: called with less than two arguments"));
- res = 0; /* silence compiler warning */
- for (i = 1; nargs > 0; nargs--, i++) {
+ res = 0; /* start with all zeroes */
+ for (; nargs > 0; nargs--) {
s1 = POP_SCALAR();
if (do_lint && (fixtype(s1)->flags & NUMBER) == 0)
lintwarn(_("xor: argument %d is non-numeric"), nargs);
@@ -3545,10 +3544,7 @@ do_xor(int nargs)
fatal(_("xor: argument %d negative value %g is not allowed"), nargs, val);
uval = (uintmax_t) val;
- if (i == 1)
- res = uval;
- else
- res ^= uval;
+ res ^= uval;
DEREF(s1);
}