From acf19fc9190985f643af06293141a1083f032563 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 23 Oct 2013 19:17:11 +0200 Subject: Use offsetof() in io.c This silences the following UBSan errors: beam/io.c:7131:27: runtime error: member access within null pointer of type 'ErlDrvSysInfo' beam/io.c:7140:20: runtime error: member access within null pointer of type 'ErlDrvSysInfo' beam/io.c:7166:20: runtime error: member access within null pointer of type 'ErlDrvSysInfo' beam/io.c:7174:20: runtime error: member access within null pointer of type 'ErlDrvSysInfo' --- erts/emulator/beam/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/emulator') diff --git a/erts/emulator/beam/io.c b/erts/emulator/beam/io.c index edf4a28784..c34a5b17d0 100644 --- a/erts/emulator/beam/io.c +++ b/erts/emulator/beam/io.c @@ -7166,7 +7166,7 @@ char *driver_dl_error(void) #define ERL_DRV_SYS_INFO_SIZE(LAST_FIELD) \ - (((size_t) &((ErlDrvSysInfo *) 0)->LAST_FIELD) \ + (offsetof(ErlDrvSysInfo, LAST_FIELD) \ + sizeof(((ErlDrvSysInfo *) 0)->LAST_FIELD)) void -- cgit v1.2.1 From a8cbf025f6e20a68b6575747200be149c6c09932 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 23 Oct 2013 19:34:57 +0200 Subject: Properly handle SINT_MIN in small_to_big() As there is no overflow for signed integers, -SINT_MIN is undefined behaviour and the cast to unsigned needs to happen before negation. SINT_MIN denotes the minimum value that can be stored in the Sint type. beam/big.c:1512:6: runtime error: negation of -9223372036854775808 cannot be represented in type 'Sint' (aka 'long'); cast to an unsigned type to negate this value to itself --- erts/emulator/beam/big.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'erts/emulator') diff --git a/erts/emulator/beam/big.c b/erts/emulator/beam/big.c index 41a041eba6..4d087bf967 100644 --- a/erts/emulator/beam/big.c +++ b/erts/emulator/beam/big.c @@ -1506,13 +1506,15 @@ Eterm uword_to_big(UWord x, Eterm *y) */ Eterm small_to_big(Sint x, Eterm *y) { + Uint xu; if (x >= 0) { + xu = x; *y = make_pos_bignum_header(1); } else { - x = -x; + xu = -(Uint)x; *y = make_neg_bignum_header(1); } - BIG_DIGIT(y, 0) = x; + BIG_DIGIT(y, 0) = xu; return make_big(y); } -- cgit v1.2.1