diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-28 23:16:58 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-28 23:16:58 +0000 |
commit | 7cbcd1cbf44df893c8c289ea3c9f03fb62b8b152 (patch) | |
tree | 0f7f7c762dc684ffb49cb64e2b4231692bc5dda8 /editors | |
parent | 996a61475a7204f17dbaa1960b123b1233027f0f (diff) | |
download | busybox-7cbcd1cbf44df893c8c289ea3c9f03fb62b8b152.tar.gz |
awk: bitwise ops cast oprands and results to unsigned long,
not signed. closes 4774.
Diffstat (limited to 'editors')
-rw-r--r-- | editors/awk.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/editors/awk.c b/editors/awk.c index 19f48401e..72eca245f 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2039,28 +2039,30 @@ static var *exec_builtin(node *op, var *res) setvar_p(res, s); break; + /* Bitwise ops must assume that operands are unsigned. GNU Awk 3.1.5: + * awk '{ print or(-1,1) }' gives "4.29497e+09", not "-2.xxxe+09" */ case B_an: - setvar_i(res, (long)getvar_i(av[0]) & (long)getvar_i(av[1])); + setvar_i(res, (unsigned long)getvar_i(av[0]) & (unsigned long)getvar_i(av[1])); break; case B_co: - setvar_i(res, ~(long)getvar_i(av[0])); + setvar_i(res, ~(unsigned long)getvar_i(av[0])); break; case B_ls: - setvar_i(res, (long)getvar_i(av[0]) << (long)getvar_i(av[1])); + setvar_i(res, (unsigned long)getvar_i(av[0]) << (unsigned long)getvar_i(av[1])); break; case B_or: - setvar_i(res, (long)getvar_i(av[0]) | (long)getvar_i(av[1])); + setvar_i(res, (unsigned long)getvar_i(av[0]) | (unsigned long)getvar_i(av[1])); break; case B_rs: - setvar_i(res, (long)((unsigned long)getvar_i(av[0]) >> (unsigned long)getvar_i(av[1]))); + setvar_i(res, (unsigned long)getvar_i(av[0]) >> (unsigned long)getvar_i(av[1])); break; case B_xo: - setvar_i(res, (long)getvar_i(av[0]) ^ (long)getvar_i(av[1])); + setvar_i(res, (unsigned long)getvar_i(av[0]) ^ (unsigned long)getvar_i(av[1])); break; case B_lo: |