multi_heap: ensure that malloc(0) return NULL pointer in any poisoning configuration
This commit is contained in:
parent
c604f980d2
commit
4a9160a72c
2 changed files with 10 additions and 0 deletions
|
@ -184,6 +184,10 @@ static bool verify_fill_pattern(void *data, size_t size, bool print_errors, bool
|
||||||
|
|
||||||
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size)
|
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size)
|
||||||
{
|
{
|
||||||
|
if (!size) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(size > SIZE_MAX - POISON_OVERHEAD) {
|
if(size > SIZE_MAX - POISON_OVERHEAD) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,3 +132,9 @@ TEST_CASE("unreasonable allocs should all fail", "[heap]")
|
||||||
TEST_ASSERT_NULL(test_malloc_wrapper(xPortGetFreeHeapSize() - 1));
|
TEST_ASSERT_NULL(test_malloc_wrapper(xPortGetFreeHeapSize() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("malloc(0) should return a NULL pointer", "[heap]")
|
||||||
|
{
|
||||||
|
void *p;
|
||||||
|
p = malloc(0);
|
||||||
|
TEST_ASSERT(p == NULL);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue