HAL_ChibiOS: ensure malloc returns zeroed memory

This commit is contained in:
Andrew Tridgell 2018-01-05 18:20:49 +11:00
parent e255f07022
commit 86fbdcd060
1 changed files with 11 additions and 1 deletions

View File

@ -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);