Module: wine Branch: master Commit: a9689eb62c6bd35aecb00f83216f04fe2ba96c74 URL: https://gitlab.winehq.org/wine/wine/-/commit/a9689eb62c6bd35aecb00f83216f04f...
Author: Alexandre Julliard julliard@winehq.org Date: Wed May 22 22:28:33 2024 +0200
msvcrt/tests: Use function pointers to bypass builtin malloc/realloc.
---
dlls/msvcrt/tests/heap.c | 50 +++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 20 deletions(-)
diff --git a/dlls/msvcrt/tests/heap.c b/dlls/msvcrt/tests/heap.c index a747482130d..e6de728f2b7 100644 --- a/dlls/msvcrt/tests/heap.c +++ b/dlls/msvcrt/tests/heap.c @@ -467,6 +467,35 @@ static void test_sbheap(void) free(mem); }
+static void test_malloc(void) +{ + /* use function pointers to bypass gcc builtins */ + void *(__cdecl *p_malloc)(size_t); + void *(__cdecl *p_realloc)(void *,size_t); + void *mem; + + p_malloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "malloc"); + p_realloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "realloc"); + + mem = p_malloc(0); + ok(mem != NULL, "memory not allocated for size 0\n"); + free(mem); + + mem = p_realloc(NULL, 10); + ok(mem != NULL, "memory not allocated\n"); + + mem = p_realloc(mem, 20); + ok(mem != NULL, "memory not reallocated\n"); + + mem = p_realloc(mem, 0); + ok(mem == NULL, "memory not freed\n"); + + mem = p_realloc(NULL, 0); + ok(mem != NULL, "memory not (re)allocated for size 0\n"); + + free(mem); +} + static void test_calloc(void) { /* use function pointer to bypass gcc builtin */ @@ -496,27 +525,8 @@ static void test_calloc(void)
START_TEST(heap) { - void *mem; - - mem = malloc(0); - ok(mem != NULL, "memory not allocated for size 0\n"); - free(mem); - - mem = realloc(NULL, 10); - ok(mem != NULL, "memory not allocated\n"); - - mem = realloc(mem, 20); - ok(mem != NULL, "memory not reallocated\n"); - - mem = realloc(mem, 0); - ok(mem == NULL, "memory not freed\n"); - - mem = realloc(NULL, 0); - ok(mem != NULL, "memory not (re)allocated for size 0\n"); - - free(mem); - test_aligned(); test_sbheap(); + test_malloc(); test_calloc(); }