From: Lukas Jiriste Date: Thu, 1 Aug 2024 10:03:40 +0000 (+0200) Subject: Fix invalid read in ft_split X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=61db70482c4aa1f7f3959148cd219c130dc63e91;p=Libft.git Fix invalid read in ft_split This read happens when the last word ends with the terminating '\0'. After advancing the index to the '\0' it is then increased once more to regions not accessible. This is fixed by simple skipping the ++i after a word has been processed. --- diff --git a/ft_str/ft_split.c b/ft_str/ft_split.c index a9bd121..641ca25 100644 --- a/ft_str/ft_split.c +++ b/ft_str/ft_split.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/20 11:51:05 by ljiriste #+# #+# */ -/* Updated: 2024/07/21 18:53:26 by ljiriste ### ########.fr */ +/* Updated: 2024/08/01 11:56:05 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,8 @@ char **ft_split(const char *str, const char *seps) res[str_num++] = extract_substr(&str[i], seps); i += substr_len(&str[i], seps); } - ++i; + else + ++i; } res[str_num] = NULL; return (res);