jgigault / 42FileChecker

42FileChecker is a tiny bash script developed at 42 school for testing and checking files according to the rules of the subjects
Apache License 2.0
306 stars 56 forks source link

Lack of test for ft_strsplit #120

Closed Rooxr closed 5 years ago

Rooxr commented 6 years ago

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);

} `

Anyway thank you for this amazing tool !!!

jgigault commented 5 years ago

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: