aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_init.c
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2014-08-04 12:04:45 +0200
committerLukas Larsson <[email protected]>2014-08-08 17:17:18 +0200
commit9d3c22934491afe85fbcf8543ae43fb2eb1ab387 (patch)
tree4cfbd2f87d60b7a143426140984a3ae0b93d9252 /erts/emulator/beam/erl_init.c
parent62081266545df8f5eda8e2043f33055cfe575126 (diff)
downloadotp-9d3c22934491afe85fbcf8543ae43fb2eb1ab387.tar.gz
otp-9d3c22934491afe85fbcf8543ae43fb2eb1ab387.tar.bz2
otp-9d3c22934491afe85fbcf8543ae43fb2eb1ab387.zip
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.
Diffstat (limited to 'erts/emulator/beam/erl_init.c')
-rw-r--r--erts/emulator/beam/erl_init.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c
index 5e6d812242..88c4006934 100644
--- a/erts/emulator/beam/erl_init.c
+++ b/erts/emulator/beam/erl_init.c
@@ -2066,8 +2066,10 @@ erl_exit_vv(int n, int flush_async, char *fmt, va_list args1, va_list args2)
system_cleanup(flush_async);
save_statistics();
-
- an = abs(n);
+ if (n < 0)
+ an = -(unsigned int)n;
+ else
+ an = n;
if (erts_mtrace_enabled)
erts_mtrace_exit((Uint32) an);