mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'backport/malloc_zero_return_null_v4.1' into 'release/v4.1'
backport/malloc_zero_return_null_v4.1 See merge request espressif/esp-idf!8146
This commit is contained in:
commit
a5bf353e3f
@ -187,6 +187,10 @@ static bool verify_fill_pattern(void *data, size_t size, bool print_errors, bool
|
||||
|
||||
void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t alignment)
|
||||
{
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size > SIZE_MAX - POISON_OVERHEAD) {
|
||||
return NULL;
|
||||
}
|
||||
@ -213,6 +217,10 @@ void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t ali
|
||||
|
||||
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size)
|
||||
{
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(size > SIZE_MAX - POISON_OVERHEAD) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -159,4 +159,11 @@ TEST_CASE("Capabilities aligned calloc test", "[heap]")
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("aligned_alloc(0) should return a NULL pointer", "[heap]")
|
||||
{
|
||||
void *p;
|
||||
p = heap_caps_aligned_alloc(32, 0, MALLOC_CAP_DEFAULT);
|
||||
TEST_ASSERT(p == NULL);
|
||||
}
|
@ -127,3 +127,9 @@ TEST_CASE("unreasonable allocs should all fail", "[heap]")
|
||||
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 New Issue
Block a user