added argument protection
This commit is contained in:
31
ft_strtrim.c
31
ft_strtrim.c
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/04/07 17:00:34 by tmaze #+# #+# */
|
||||
/* Updated: 2018/04/08 16:33:22 by tmaze ### ########.fr */
|
||||
/* Updated: 2018/04/10 14:15:23 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,22 +20,23 @@ char *ft_strtrim(char const *s)
|
||||
size_t len;
|
||||
|
||||
i = 0;
|
||||
start = 0;
|
||||
len = 0;
|
||||
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
|
||||
i++;
|
||||
start = i;
|
||||
in_word = 1;
|
||||
while (i == 0 || s[i - 1])
|
||||
if (s != NULL)
|
||||
{
|
||||
if (in_word && (!ft_isprint(s[i]) || s[i] == ' '))
|
||||
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
|
||||
i++;
|
||||
start = i;
|
||||
in_word = 1;
|
||||
while (i == 0 || s[i - 1])
|
||||
{
|
||||
len = i - start;
|
||||
in_word = 0;
|
||||
if (in_word && (!ft_isprint(s[i]) || s[i] == ' '))
|
||||
{
|
||||
len = i - start;
|
||||
in_word = 0;
|
||||
}
|
||||
else if (!in_word && ft_isprint(s[i]) && s[i] != ' ')
|
||||
in_word = 1;
|
||||
i++;
|
||||
}
|
||||
else if (!in_word && ft_isprint(s[i]) && s[i] != ' ')
|
||||
in_word = 1;
|
||||
i++;
|
||||
}
|
||||
return (ft_strsub(s, start, len));
|
||||
return ((s != NULL) ? ft_strsub(s, start, len) : NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user