mempool: add assertion for calloc bounds overflow
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
c87ecf58de
commit
a79c69823f
1 changed files with 6 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue