xicodomingues / francinette

An easy to use testing framework for the 42 projects
MIT License
463 stars 44 forks source link

[BUG] Libft tests may has a problem with the `ft_lstmap` function #72

Closed pioupia closed 11 months ago

pioupia commented 11 months ago

Describe the bug

Additional information

2023-10-21 09:37:19,196 [fsoares][INFO]: copying sanitized libft.a from /nfs/homes//francinette/temp/libft/fsoares/../__my_srcs to /nfs/homes//francinette/temp/libft/fsoares
2023-10-21 09:37:19,204 [fsoares][INFO]: On directory /nfs/homes//francinette/temp/libft/fsoares
2023-10-21 09:37:19,204 [fsoares][INFO]: executing gcc -g   -D TIMEOUT=2 -Wall -Wextra -Werror -Wno-deprecated-declarations my_utils.c  list_utils.c test_lstmap.c utils/malloc_mock.c utils/utils.c -L. -lft -o test_lstmap.out -ldl
2023-10-21 09:37:19,498 [fsoares][INFO]: CompletedProcess(args='gcc -g   -D TIMEOUT=2 -Wall -Wextra -Werror -Wno-deprecated-declarations my_utils.c  list_utils.c test_lstmap.c utils/malloc_mock.c utils/utils.c -L. -lft -o test_lstmap.out -ldl', returncode=0, stdout='', stderr='')
free(): invalid pointer
2.KO Abort

2023-10-21 09:37:19,730 [base][ERROR]: 'NoneType' object has no attribute 'group'
Traceback (most recent call last):
  File "/nfs/homes//francinette/testers/BaseTester.py", line 183, in test_using
    return (tester.name, tx.execute())
  File "/nfs/homes//francinette/testers/libft/Fsoares.py", line 45, in execute
    result = self.execute_tests()
  File "/nfs/homes//francinette/testers/libft/Fsoares.py", line 139, in execute_tests
    result = [execute_test(func) for func in self.to_execute]
  File "/nfs/homes//francinette/testers/libft/Fsoares.py", line 139, in <listcomp>
    result = [execute_test(func) for func in self.to_execute]
  File "/nfs/homes//francinette/testers/libft/Fsoares.py", line 137, in execute_test
    return parse_output(remove_ansi_colors(output), func)
  File "/nfs/homes//francinette/testers/libft/Fsoares.py", line 109, in parse_output
    return (match.group(1), match.group(2), lines)
AttributeError: 'NoneType' object has no attribute 'group'

I think I know why it does this. In the /nfs/homes//francinette/tests/libft/fsoares/test_lstmap.c file, line 19, the contents are freed. So you'd think that's fine, but if we take a closer look at the code, we see how tests are generated line 60. We can see that you're passing a freshly created string to the create_list function, so for the moment, the string is store on the stack. Then, it goes to the create_list function, and to the lstnew function. But I didn't see any strdup or anything to duplicate the string in the heap. So, as far as I'm concerned, the string is still in the heap and can't be moved from there. After that, you're trying to free something you can't, so we get an error.