From a4fbc385e0910510b0e46007a51c8d48609e88a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Tue, 5 Apr 2016 21:36:34 +0200 Subject: [PATCH] libpayload/libc: Fix memset/sizeof usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since r is a pointer, memset(r, 0, sizeof(r)) would only zero the first 4 (or 8) bytes of the newly allocated struct align_region_t. An alternative to this patch would be to use calloc, or introduce a new zalloc (zeroed allocation; a single-element calloc) and use that. Change-Id: Ic3e3487ce749eeebf6c4836e62b8a305ad766e7e Found-by: Coverity (ID 1291160) Signed-off-by: Jonathan Neuschäfer Reviewed-on: https://review.coreboot.org/14244 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel --- payloads/libpayload/libc/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c index 7099e47ed4..b7ac1a7c60 100644 --- a/payloads/libpayload/libc/malloc.c +++ b/payloads/libpayload/libc/malloc.c @@ -366,7 +366,7 @@ static struct align_region_t *allocate_region(int alignment, int num_elements, if (r == NULL) return NULL; - memset(r, 0, sizeof(r)); + memset(r, 0, sizeof(*r)); if (num_elements != 0) { r->alignment = alignment;