From e8becad96454a8deb755f587ca0daaf96dfca90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 10 May 2011 10:56:24 +0200 Subject: Fix construction of <<0:((1 bsl 32)-1)>> Attempting to construct <<0:((1 bsl 32)-1)>>, the largest bitstring allowed in a 32 bit emulator, would cause an emulator crash because of integer overflow. Fix the problem by using an Uint64 to avoid integer overflow. Do not attempt to handle construction of <<0:((1 bsl 64)-1>> in a 64-bit emulator, because that will certainly cause the emulator to terminate anyway because of insufficient memory. --- erts/emulator/beam/erl_bits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/emulator/beam/erl_bits.h') diff --git a/erts/emulator/beam/erl_bits.h b/erts/emulator/beam/erl_bits.h index 0f67733fa4..3309ea706b 100644 --- a/erts/emulator/beam/erl_bits.h +++ b/erts/emulator/beam/erl_bits.h @@ -150,7 +150,7 @@ void erts_bits_destroy_state(ERL_BITS_PROTO_0); * NBYTES(x) returns the number of bytes needed to store x bits. */ -#define NBYTES(x) (((x) + 7) >> 3) +#define NBYTES(x) (((Uint64)(x) + (Uint64) 7) >> 3) #define BYTE_OFFSET(ofs) ((Uint) (ofs) >> 3) #define BIT_OFFSET(ofs) ((ofs) & 7) -- cgit v1.2.3