From 9a5097380d83ce777e4871f88116800b7036a5ec Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 1 Aug 2024 09:30:06 +0200 Subject: [PATCH] Make sure t_vecs are initialized before free Short circuiting was meant to save the computation resources but causes assignments not to be initialized when redirections encounter a problem. This could be solved by initializing assignments outside of save_assignments or by letting save_assignments initialize the assignments even though it won't be used. I opted for the later. --- src/execution.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/execution.c b/src/execution.c index 8169c6b..18effc9 100644 --- a/src/execution.c +++ b/src/execution.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */ -/* Updated: 2024/07/22 22:54:45 by ljiriste ### ########.fr */ +/* Updated: 2024/08/01 09:28:18 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -112,7 +112,7 @@ int save_assignments(t_vec *assignments, t_parse_tree_node *simple_command, cons char *get_word(const t_parse_tree_node *parent) { char *res; - const t_parse_tree_node *word = ft_vec_caccess(&parent->children, 2); + const t_parse_tree_node *word = ft_vec_caccess(&parent->children, 0); res = ft_strdup(word->token.str); return (res); @@ -608,7 +608,8 @@ int ex_simple_command(t_parse_tree_node *simple_command, t_execution_env *env) int res; res = save_redirections(&redirections, simple_command, env); - res = res || save_assignments(&assignments, simple_command, env); + res = save_assignments(&assignments, simple_command, env) || res; + fields = NULL; if (!res) fields = expand(simple_command, env); if (!fields || res) -- 2.30.2