From 9d3c22934491afe85fbcf8543ae43fb2eb1ab387 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 4 Aug 2014 12:04:45 +0200 Subject: erts: Fix neg int overflow when sint is min size When INT64_MIN is the value of a Sint64 we have to first cast it to an Uint64 before negating it. Otherwise we get an integer overflow which is undefined behaviour and in gcc 4.9 this results in -0 instead of -9223372036854775808 in gcc 4.8. --- erts/emulator/beam/big.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/emulator/beam/big.h') diff --git a/erts/emulator/beam/big.h b/erts/emulator/beam/big.h index d80111822e..da31876d75 100644 --- a/erts/emulator/beam/big.h +++ b/erts/emulator/beam/big.h @@ -101,7 +101,7 @@ typedef Uint dsize_t; /* Vector size type */ #define ERTS_SINT64_HEAP_SIZE(X) \ (IS_SSMALL((X)) \ ? 0 \ - : ERTS_UINT64_BIG_HEAP_SIZE__((X) >= 0 ? (X) : -(X))) + : ERTS_UINT64_BIG_HEAP_SIZE__((X) >= 0 ? (X) : -(Uint64)(X))) #define ERTS_UINT64_HEAP_SIZE(X) \ (IS_USMALL(0, (X)) ? 0 : ERTS_UINT64_BIG_HEAP_SIZE__((X))) -- cgit v1.2.3