From: Lukas Jiriste Date: Sat, 15 Jun 2024 08:17:54 +0000 (+0200) Subject: Fix a logic bug X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=4a8575817f963e4c48367a4e8e506014f950f902;p=Libft.git Fix a logic bug --- diff --git a/ft_parse/ft_parse.c b/ft_parse/ft_parse.c index 0e11486..259a826 100644 --- a/ft_parse/ft_parse.c +++ b/ft_parse/ft_parse.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/20 20:51:36 by ljiriste #+# #+# */ -/* Updated: 2024/06/15 09:24:56 by ljiriste ### ########.fr */ +/* Updated: 2024/06/15 10:06:32 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,6 +74,8 @@ static t_grammar_rule parse_rule(const char *line) j = i; while (!ft_isspace(line[i]) && line[i]) ++i; + if (j == i) + break ; token.type = ft_strndup(line + j, i - j); ft_vec_append(&rule.constituents, &token); } @@ -109,7 +111,7 @@ static int load_rules(t_vec *rules, const char *rules_filename) while (line) { rule = parse_rule(line); - if (!is_valid_rule(&rule) && ft_vec_append(rules, &rule)) + if (!is_valid_rule(&rule) || ft_vec_append(rules, &rule) != success) { ft_vec_free(rules, free_rule); return (2);