Fix some minor issues
authorLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 22:11:49 +0000 (00:11 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 22:11:49 +0000 (00:11 +0200)
Of by one errors, missing free and such.

src/env.c
src/execution.c

index 4f7e5808f33208796b34872d43274bf5e331d55a..8d6829cb3f22d3c6353adb5695afe9e75e655e3c 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/07/21 21:24:52 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/07/21 21:34:58 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/07/21 23:46:03 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -33,6 +33,7 @@ int   init_env(t_execution_env *env, char **envp)
 void   clean_env(t_execution_env *env)
 {
        clean_vars(env->vars);
+       free(env->vars);
        ft_vec_free(&env->redirections, NULL);
        return ;
 }
index f342bcfd87b4cda2623885dc4426693dbfc9de16..259d6522946c866a38432e465c98fb6706e8f27b 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/07/21 08:57:54 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/07/21 21:19:33 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/07/22 00:09:18 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -164,8 +164,10 @@ const char *get_var_value(const t_vec *vars, const char *var_name)
        while (i < vars->size)
        {
                line = ft_vec_caccess(vars, i);
-               if (ft_strncmp(*line, var_name, len) && (*line)[len + 1] == '=')
-                       return (*line + len + 2);
+               if (!*line)
+                       break ;
+               if (!ft_strncmp(*line, var_name, len) && (*line)[len] == '=')
+                       return (*line + len + 1);
                ++i;
        }
        return (NULL);
@@ -361,12 +363,15 @@ int       save_redirections(t_vec *redirections, t_parse_tree_node *simple_command, co
        return (0);
 }
 
+static const char      space = ' ';
+
 int    add_word(t_vec *exp_str, const char *word, const t_execution_env *env)
 {
        size_t          i;
        char            *var;
        const char      *value;
 
+       i = 0;
        while (word[i])
        {
                if (word[i] == '$')
@@ -386,6 +391,8 @@ int add_word(t_vec *exp_str, const char *word, const t_execution_env *env)
                        if (ft_vec_append(exp_str, word + (i++)) != success)
                                return (1);
        }
+       if (ft_vec_append(exp_str, &space) != success)
+               return (1);
        return (0);
 }
 
@@ -469,6 +476,7 @@ int ex_fields(char **fields,__attribute__((unused)) const t_vec *assignments,__a
 {
        size_t  i;
 
+       i = 0;
        while (fields[i])
                ft_printf("%s\n", fields[i++]);
        return (0);
@@ -496,6 +504,7 @@ int ex_simple_command(t_parse_tree_node *simple_command, t_execution_env *env)
                assignments_to_env(&assignments, env);
                ft_vec_free(&redirections, NULL);
                ft_vec_free(&assignments, NULL);
+               free_fields(fields);
                return (0);
        }
        res = ex_fields(fields, &assignments, &redirections, env);