Make sure t_vecs are initialized before free
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 1 Aug 2024 07:30:06 +0000 (09:30 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 1 Aug 2024 07:30:06 +0000 (09:30 +0200)
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

index 8169c6bce9538928c312947566bb3736db28369c..18effc9cfd9fb5bf19350e230a7fe334c94b92f9 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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)