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.
This commit is contained in:
herman ten brugge 2023-09-07 20:05:51 +02:00
parent 086870addd
commit 9bb9a04b5f
2 changed files with 13 additions and 5 deletions

View File

@ -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;
if (size == 0) {
free(ptr);
ptr1 = NULL;
}
else {
ptr1 = realloc(ptr, size);
if (!ptr1 && size)
if (!ptr1)
mem_error("memory full (realloc)");
}
return ptr1;
}

View File

@ -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