From: Lukas Jiriste Date: Fri, 21 Jun 2024 08:57:50 +0000 (+0200) Subject: Fix bug, where NULLs appear inside tree X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=3abc55033ec23bf1d3593e60843263033b16b409;p=Libft.git 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. --- 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);