From c8d3bff46adbff3205eaf76de8a634557cbd4af4 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 17 Dec 2018 16:03:36 +0100 Subject: erts: Fix bug in 'band' of two negative numbers, one big Similar bug as for bxor fixed by abc4fd372d476821448dfb9 Ex: 1> io:format("~.16B\n", [-16#1110000000000000000 band (-1)]). -1120000000000000000 Wrong result for (-X bsl WS) band -Y. where X is any positive integer WS is erlang:system_info(wordsize)*8*N where N is 1 or larger Y is any positive integer smaller than (1 bsl WS) Fix: The subtraction of 1 (for 2-complement conversion) must be carried along all the way to the last words. --- erts/emulator/beam/big.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'erts/emulator/beam') diff --git a/erts/emulator/beam/big.c b/erts/emulator/beam/big.c index 323cd6c518..6497089419 100644 --- a/erts/emulator/beam/big.c +++ b/erts/emulator/beam/big.c @@ -1139,8 +1139,11 @@ static dsize_t I_band(ErtsDigit* x, dsize_t xl, short xsgn, *r++ = ~c1 & ~c2; x++; y++; } - while(xl--) - *r++ = ~*x++; + while(xl--) { + DSUBb(*x,0,b1,c1); + *r++ = ~c1; + x++; + } } } return I_btrail(r0, r, sign); -- cgit v1.2.3