aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src/legacy
diff options
context:
space:
mode:
authorMikael Pettersson <[email protected]>2018-04-21 14:08:14 +0200
committerMikael Pettersson <[email protected]>2018-04-21 14:08:14 +0200
commitbd31798262cd20354e64cca8654b0781b33d7ede (patch)
tree1f2d3ec36e48bc9e1e4ba40e5f9cb1f6a88ece55 /lib/erl_interface/src/legacy
parent0343b68b053ee97b2ef70ea07b9aa87e8842c591 (diff)
downloadotp-bd31798262cd20354e64cca8654b0781b33d7ede.tar.gz
otp-bd31798262cd20354e64cca8654b0781b33d7ede.tar.bz2
otp-bd31798262cd20354e64cca8654b0781b33d7ede.zip
erl_interface: fix bad memset
Compiling OTP-20.3.4 with GCC-7 generates the following warning: CC /tmp/otp_src_20.3.4/lib/erl_interface/obj.st/x86_64-unknown-linux-gnu/erl_marshal.o legacy/erl_marshal.c: In function 'erl_init_marshal': legacy/erl_marshal.c:110:5: warning: 'memset' used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size] memset(cmp_array, 0, CMP_ARRAY_SIZE); ^~~~~~ CMP_ARRAY_SIZE (256) is the number of elements in that array, but the elements are not char but enum, which is 4 bytes on e.g. x86-64. This results in 3/4 of the array not being correctly initialized. Idiomatic C is to pass sizeof cmp_array to memset(), so that's what I did.
Diffstat (limited to 'lib/erl_interface/src/legacy')
-rw-r--r--lib/erl_interface/src/legacy/erl_marshal.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/erl_interface/src/legacy/erl_marshal.c b/lib/erl_interface/src/legacy/erl_marshal.c
index caa171858d..6435754823 100644
--- a/lib/erl_interface/src/legacy/erl_marshal.c
+++ b/lib/erl_interface/src/legacy/erl_marshal.c
@@ -107,7 +107,7 @@ static int init_cmp_num_class_p=1; /* initialize array, the first time */
void erl_init_marshal(void)
{
if (init_cmp_array_p) {
- memset(cmp_array, 0, CMP_ARRAY_SIZE);
+ memset(cmp_array, 0, sizeof cmp_array);
cmp_array[ERL_SMALL_INTEGER_EXT] = ERL_NUM_CMP;
cmp_array[ERL_INTEGER_EXT] = ERL_NUM_CMP;
cmp_array[ERL_FLOAT_EXT] = ERL_NUM_CMP;