alelievr / libft-unit-test

455 stars 88 forks source link

Detecting a malloc before **ptr malloc in ft_split #99

Closed wwwwelton closed 3 years ago

wwwwelton commented 3 years ago

If a malloc ocurs before **ptr malloc, to search size of elements, the test crash. If I change the ptr malloc before str malloc, the test pass, but I need to know the correct size of elements.

ft_split

code => if (!s) return (NULL); str = ft_strsubsep(ft_strdup(s), c, c); size = ft_strelem(str, c) + 1; ptr = (char *)malloc(sizeof(char ) * size); if (!ptr) return (NULL);

ft_split2

code passing => ptr = (char *)malloc(sizeof(char ) * 6); if (!ptr) return (NULL); if (!s) return (NULL); str = ft_strsubsep(ft_strdup(s), c, c); size = ft_strelem(str, c) + 1;

ft_strsubsep is a functions thats trim multiples ocorrences of a character and uses malloc and free. If u need the entire code reply me.