From 11aeaaf8deeb265ac98cbabfa501d2da155475d7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 31 Jul 2020 23:47:45 +0200 Subject: The hell it works, now asan lol --- src/p_lcom_next.c | 68 ++++++++++++++++++++++++++++++++----------------------- src/s_lcom.c | 3 +-- 2 files changed, 41 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index e3f1dfa..f340294 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -15,10 +15,14 @@ #include #include "d_enum.h" +#include "s_destroy.h" +#include "f_fail.h" #include "s_struct.h" #include "u_vars.h" #include "u_vars_next.h" +/* TODO: norme */ + static int8_t subst_those_vars(int64_t i, char **p_words, @@ -124,69 +128,77 @@ static void i++; ptr++; } + val[i] = '\0'; u_subst_var_value(name, val, msh); } static char **p_add_to_variables_and_delete( /* t_bool equals[], */ char *words[], + t_bool reg, int64_t i, t_msh *msh) { - char *ptr; - t_bool reg; int64_t j; + int64_t k; + char **rewords; - reg = FALSE; - ptr = words[i - 1]; - while (*ptr != '\0' && *ptr != '=') - { - ptr++; - } - if (*ptr != '\0') - { - reg = TRUE; - } j = 0; if (reg == TRUE) { - while (words[j]) + while (words[j] && j < i) { p_register_word(words[j], msh); j++; } } j = 0; - while (j < i) - { - ft_memdel((void*)&words[0]); - words = words + 1; + while (words[i + j] != NULL) j++; + if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) + { + ft_delwords(words); + s_destroy(msh); + f_fail_alloc(msh); } - return (words); + k = i; + while (i - k < j) + { + if (!(rewords[i - k] = ft_strdup(words[i]))) + { + ft_delwords(words); + s_destroy(msh); + f_fail_alloc(msh); + } + i++; + } + rewords[i - k] = 0; + ft_delwords(words); + i++; + return (rewords); } char **p_check_args_equals(char *words[], t_msh *msh) { - /* t_bool equals[255]; */ char *ptr; + t_bool reg; int64_t i; - /* i = -1; */ - /* while (++i < 255) */ - /* equals[i] = FALSE; */ - i = -1; - while (words[++i]) + i = 0; + reg = TRUE; + while (words[i]) { ptr = words[i]; while (*ptr != '\0' && *ptr != '=') ptr++; - /* if (*ptr != '\0') */ - /* equals[i] = TRUE; */ - if (*ptr == '\0') + if (*ptr == '\0' || words[i][0] == '=') + { + reg = FALSE; break ; + } + i++; } - return (p_add_to_variables_and_delete(/* equals, */words, i, msh)); + return (p_add_to_variables_and_delete(/* equals, */words, reg, i, msh)); } diff --git a/src/s_lcom.c b/src/s_lcom.c index 088f625..f1ef2a4 100644 --- a/src/s_lcom.c +++ b/src/s_lcom.c @@ -138,7 +138,6 @@ t_lcom return (NULL); } link->next = NULL; - if (words[0] != NULL) - ft_delwords(words); + ft_delwords(words); return (link); } -- cgit v1.2.3