Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
removed some leaks from substr
Browse files Browse the repository at this point in the history
  • Loading branch information
nopbxlr committed May 9, 2022
1 parent 9a6bafb commit 407b7ac
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ft_substr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/09 17:31:48 by ctherin #+# #+# */
/* Updated: 2022/05/09 21:34:26 by ctherin ### ########.fr */
/* Updated: 2022/05/09 22:05:04 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -22,18 +22,20 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
if (!s)
return (NULL);
d = (char *)s;
ptr = ft_calloc(len + 1, sizeof(char));
if (!ptr)
return (NULL);
if (start < ft_strlen(s))
{
if (ft_strlen(s) < len)
len = ft_strlen(s) - start;
ptr = ft_calloc(len + 1, sizeof(char));
if (!ptr)
return (NULL);
while (i < len && d[start + i])
{
ptr[i] = d[i + start];
i++;
}
return (ptr);
}
else
return (ft_calloc(1, sizeof(char)));
return (ptr);
}

0 comments on commit 407b7ac

Please sign in to comment.