alelievr / libft-unit-test

453 stars 88 forks source link

Fix defining calloc as receiving only one parameter #134

Closed xicodomingues closed 1 year ago

xicodomingues commented 1 year ago

The first calloc test in libft-unit-test tester timeouts on my laptop but not in school.

I looked at the test, and I think that the problem is in the test rather than in my code. In all other calloc tester functions the pointer to the tested function is casted to typeof(calloc)* like this but in test_ft_calloc_free it is casted to void *(*)(size_t) like this. Later it is called with one param. But that's UB because ft_calloc has 2 params.

I suggest replacing

void *  (*ft_calloc)(size_t) = ptr;
...
free(ft_calloc(42));

with

typeof(calloc)  *ft_calloc = ptr;
...
free(ft_calloc(42, 1));

or whatever value of the second parameter makes sense.

First reported here by @Oktosha https://github.com/xicodomingues/francinette/issues/15

MalwarePup commented 1 year ago

Thanks for fix @xicodomingues!