Hi there,
I just discovered that my ft_strsplit passed all the test of 42FileChecker but was killed by a segfault during moulinette test
I find it strange though cause I remembered fixing this earlier...
I tested "Hello World !" with separation character being " "
I managed to recreate the segfault this way
Here was my code :
`#include "libft.h"
static int ft_countw(char const *s, char c)
{
unsigned int wc;
wc = 0;
while (*s)
{
if (*s == c)
s++;
if (*s && *s != c)
{
wc++;
while (*s && *s != c)
s++;
}
}
return (wc);
}
static int ft_wlen(char const *s, char c)
{
unsigned int wl;
wl = 0;
while (*s++ != c) // I haven't protected correctly my loop ==> memory leak when there is no c character at the end of s
wl++;
return (wl);
}
char *ft_strsplit(char const s, char c)
{
char **tab;
unsigned int i;
if (s)
{
if (!(tab = (char **)malloc(sizeof(char *) * (ft_countw(s, c) + 1))))
return (NULL);
i = 0;
while (*s)
{
if (*s == c)
s++;
if (*s && *s != c)
{
if (!(tab[i++] = ft_strsub(s, 0, ft_wlen(s, c))))
return (NULL);
}
while (*s && *s != c)
s++;
}
tab[i] = NULL;
return (tab);
}
return (NULL);
Hello @kgrosjea
Thanks for your issue and sorry for my late answer.
You should open an issue on repositories where tests are stored, because 42FC does not test libft itself:
Hi there, I just discovered that my ft_strsplit passed all the test of 42FileChecker but was killed by a segfault during moulinette test I find it strange though cause I remembered fixing this earlier... I tested "Hello World !" with separation character being " " I managed to recreate the segfault this way
Here was my code : `#include "libft.h"
static int ft_countw(char const *s, char c) { unsigned int wc;
}
static int ft_wlen(char const *s, char c) { unsigned int wl;
}
char *ft_strsplit(char const s, char c) { char **tab; unsigned int i;
} `
Anyway thank you for this amazing tool !!!