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