diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-09 17:57:57 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-09 17:57:57 +0200 |
| commit | 4e81fb861a79c9373b070176649bc0f4f8dfa850 (patch) | |
| tree | 7586abc6d769edbba10d10bf4cc419ca85471862 /src/preprocess.c | |
| parent | 5ade92701836ce5ee1d39fc8d486b7709547058e (diff) | |
| download | minishell-4e81fb861a79c9373b070176649bc0f4f8dfa850.tar.gz minishell-4e81fb861a79c9373b070176649bc0f4f8dfa850.tar.bz2 minishell-4e81fb861a79c9373b070176649bc0f4f8dfa850.zip | |
Fixing 2 leaks in preprocessor and norming it
Diffstat (limited to 'src/preprocess.c')
| -rw-r--r-- | src/preprocess.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/preprocess.c b/src/preprocess.c index 0d72a2c..c09ba71 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/03 08:58:49 by charles #+# #+# */ -/* Updated: 2020/06/09 17:03:37 by charles ### ########.fr */ +/* Updated: 2020/06/09 17:56:20 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,16 @@ #include "ms_glob.h" #include "lexer.h" -static char *iterpolate(char *str, t_env env) +static char *iterpolate(char *str, t_env env) { size_t i; t_ftdstr *dstr; char *match; - if ((dstr = ft_dstrnew(str)) == NULL) + if ((dstr = ft_dstrwrap(str)) == NULL) return (NULL); - free(str); - i = 0; - while (i < dstr->length) - { + i = -1; + while (++i < dstr->length) if (dstr->str[i] == '$') { if ((match = env_search_first_match(env, dstr->str + i + 1)) == NULL) @@ -43,8 +41,6 @@ static char *iterpolate(char *str, t_env env) i += ft_strlen(match) - 1; } } - i++; - } return (ft_dstrunwrap(dstr)); } @@ -53,13 +49,13 @@ static char *iterpolate_globs(char *str) char **strs; int i; - if ((strs = ft_split(str, ' ')) == NULL) + if ((strs = ft_splitf(str, ' ')) == NULL) return (NULL); i = 0; while (strs[i] != NULL) { if (ft_strchr(strs[i], '*') != NULL - && (strs[i] = ms_glob(strs[i])) == NULL) + && (strs[i] = ms_globf(strs[i])) == NULL) { ft_split_destroy(strs); return (NULL); @@ -69,7 +65,7 @@ static char *iterpolate_globs(char *str) return (ft_strsjoinf(strs, " ")); } -static int splat_arg(t_ftvec *argv, int i) +static int splat_arg(t_ftvec *argv, int i) { t_token *splated; char **strs; @@ -77,19 +73,24 @@ static int splat_arg(t_ftvec *argv, int i) if ((splated = ft_vectake(argv, i)) == NULL || (strs = ft_split(splated->content, ' ')) == NULL) + { + token_destroy(splated); return (-1); + } j = 0; while (strs[j] != NULL) { if (ft_vecinsert_safe(argv, i + j, token_new(LTAG_STR, strs[j])) == NULL) { + token_destroy(splated); ft_split_destroy(strs); return (-1); } j++; } + token_destroy(splated); ft_split_destroy(strs); - return i + j - 1; + return (i + j - 1); } void iter_func_unwrap_token(void **addr) |
