From 61db70482c4aa1f7f3959148cd219c130dc63e91 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 1 Aug 2024 12:03:40 +0200 Subject: [PATCH] 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. --- ft_str/ft_split.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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); -- 2.30.2