fix(mem): fix TLSF returning the wrong pointer when the requested size is too large (#3325)
* test(mem) add test for #3324 * fix(tlsf) don't return the same pointer if the requested size is too large
This commit is contained in:
@@ -1208,6 +1208,10 @@ void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size)
|
||||
const size_t cursize = block_size(block);
|
||||
const size_t combined = cursize + block_size(next) + block_header_overhead;
|
||||
const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
|
||||
if(size > cursize && adjust == 0) {
|
||||
/* The request is probably too large, fail */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tlsf_assert(!block_is_free(block) && "block already marked as free");
|
||||
|
||||
|
||||
26
tests/src/test_cases/test_mem.c
Normal file
26
tests/src/test_cases/test_mem.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
/* Function run before every test */
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Function run after every test */
|
||||
}
|
||||
|
||||
/* #3324 */
|
||||
void test_mem_buf_realloc(void)
|
||||
{
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
void * buf1 = lv_mem_alloc(20);
|
||||
void * buf2 = lv_mem_realloc(buf1, LV_MEM_SIZE + 16384);
|
||||
TEST_ASSERT_NULL(buf2);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user