awk: bitwise ops cast oprands and results to unsigned long,
not signed. closes 4774.
This commit is contained in:
parent
996a61475a
commit
7cbcd1cbf4
@ -2039,28 +2039,30 @@ static var *exec_builtin(node *op, var *res)
|
|||||||
setvar_p(res, s);
|
setvar_p(res, s);
|
||||||
break;
|
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:
|
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;
|
break;
|
||||||
|
|
||||||
case B_co:
|
case B_co:
|
||||||
setvar_i(res, ~(long)getvar_i(av[0]));
|
setvar_i(res, ~(unsigned long)getvar_i(av[0]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_ls:
|
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;
|
break;
|
||||||
|
|
||||||
case B_or:
|
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;
|
break;
|
||||||
|
|
||||||
case B_rs:
|
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;
|
break;
|
||||||
|
|
||||||
case B_xo:
|
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;
|
break;
|
||||||
|
|
||||||
case B_lo:
|
case B_lo:
|
||||||
|
Loading…
Reference in New Issue
Block a user