From 3abc55033ec23bf1d3593e60843263033b16b409 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 21 Jun 2024 10:57:50 +0200 Subject: [PATCH] Fix bug, where NULLs appear inside tree This bug was caused because the tree nodes are filled from the end when reducing. Instead of just inserting to the start it was inserting at the final position. When inserting to vector outside of range all the nonexistent entries are initialized to 0. If another insertion happes after that, the 0 entries are not filled but moved to make space for the new entry. --- ft_parse/ft_parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ft_parse/ft_parse.c b/ft_parse/ft_parse.c index e101c5c..bd1cf9d 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/21 09:39:33 by ljiriste ### ########.fr */ +/* Updated: 2024/06/21 10:56:32 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,7 +107,7 @@ int follow_rule(t_stack *stack, size_t rule_num, t_parsing_table *table) node = ((t_parser_stack_element *)ft_stack_pop(stack, NULL))->node; if (ft_strcmp(node->token.type, ((t_token *)ft_vec_access(&rule->constituents, i))->type) || - ft_vec_insert(&element.node->children, node, i) != success) + ft_vec_insert(&element.node->children, node, 0) != success) { ft_parse_tree_free(element.node); ft_parse_tree_free(node); -- 2.30.2