From 86fbdcd0604a022874a838067c5056629b9d1f51 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 5 Jan 2018 18:20:49 +1100 Subject: [PATCH] HAL_ChibiOS: ensure malloc returns zeroed memory --- libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c b/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c index 167a74646b..b85785d87e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c @@ -34,11 +34,21 @@ void *malloc(size_t size) { - return chHeapAllocAligned(NULL, size, MIN_ALIGNMENT); + if (size == 0) { + return NULL; + } + void *p = chHeapAllocAligned(NULL, size, MIN_ALIGNMENT); + if (p) { + memset(p, 0, size); + } + return p; } void *calloc(size_t nmemb, size_t size) { + if (nmemb * size == 0) { + return NULL; + } void *p = chHeapAllocAligned(NULL, nmemb*size, MIN_ALIGNMENT); if (p != NULL) { memset(p, 0, nmemb*size);