From 9bb9a04b5f84ae4cd27d4188721090c970515df5 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Thu, 7 Sep 2023 20:05:51 +0200 Subject: [PATCH] Small fixes The testcases 22_floating_point and 24_math_library did not work with make tcov-test Add -lm for these in tests/tests2/Makefile gcc -fanalyzer complains about tcc_malloc and tcc_realloc because malloc(0) and realloc(ptr, 0) is not tested correctly. --- libtcc.c | 16 +++++++++++----- tests/tests2/Makefile | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libtcc.c b/libtcc.c index 44a292d7..1dba5174 100644 --- a/libtcc.c +++ b/libtcc.c @@ -265,8 +265,8 @@ PUB_FUNC void tcc_free(void *ptr) PUB_FUNC void *tcc_malloc(unsigned long size) { void *ptr; - ptr = malloc(size); - if (!ptr && size) + ptr = malloc(size ? size : 1); + if (!ptr) mem_error("memory full (malloc)"); return ptr; } @@ -283,9 +283,15 @@ PUB_FUNC void *tcc_mallocz(unsigned long size) PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) { void *ptr1; - ptr1 = realloc(ptr, size); - if (!ptr1 && size) - mem_error("memory full (realloc)"); + if (size == 0) { + free(ptr); + ptr1 = NULL; + } + else { + ptr1 = realloc(ptr, size); + if (!ptr1) + mem_error("memory full (realloc)"); + } return ptr1; } diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index ebb271ab..49a82e9b 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -55,6 +55,8 @@ endif # Some tests might need arguments ARGS = +22_floating_point.test: FLAGS += -lm +24_math_library.test: FLAGS += -lm 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c