mempool: add assertion for calloc bounds overflow

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-11-14 12:12:33 -08:00 committed by Andrew Boie
commit a79c69823f

View file

@ -9,6 +9,7 @@
#include <wait_q.h>
#include <init.h>
#include <string.h>
#include <misc/__assert.h>
/* Linker-defined symbols bound the static pool structs */
extern struct k_mem_pool _k_mem_pool_list_start[];
@ -411,7 +412,12 @@ void *k_calloc(size_t nmemb, size_t size)
void *ret;
size_t bounds;
#ifdef CONFIG_ASSERT
__ASSERT(!__builtin_mul_overflow(nmemb, size, &bounds),
"requested size overflow");
#else
bounds = nmemb * size;
#endif
ret = k_malloc(bounds);
if (ret) {
memset(ret, 0, bounds);