added argument protection

This commit is contained in:
Tanguy MAZE
2018-04-10 15:12:32 +02:00
parent 45e39d4f0e
commit f6e6bf0680
17 changed files with 108 additions and 70 deletions

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/07 15:00:23 by tmaze #+# #+# */
/* Updated: 2018/04/07 15:00:24 by tmaze ### ########.fr */
/* Updated: 2018/04/10 14:19:19 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,9 +19,14 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
size_t s_len;
i = -1;
s_len = ft_strlen(s);
ret = ft_strnew(s_len);
while (++i < s_len)
ret[i] = (*f)(i, s[i]);
s_len = 0;
ret = NULL;
if (s != NULL && f != NULL)
{
s_len = ft_strlen(s);
if ((ret = ft_strnew(s_len)) != NULL)
while (++i < s_len)
ret[i] = (*f)(i, s[i]);
}
return (ret);
}