summaryrefslogtreecommitdiffstats
path: root/src/ft_m_loop.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-04-28 17:35:37 +0200
committersalad <fmoenne-@student.le-101.fr>2020-04-28 17:35:37 +0200
commit54d9c42870ba7b7c3380c146d549d9173e68d718 (patch)
tree69ff746c6817b5f19b9d3760921589215179a12f /src/ft_m_loop.c
parentsneaky segv, onto backslashes (diff)
download42-minishell-54d9c42870ba7b7c3380c146d549d9173e68d718.tar.gz
42-minishell-54d9c42870ba7b7c3380c146d549d9173e68d718.tar.bz2
42-minishell-54d9c42870ba7b7c3380c146d549d9173e68d718.tar.xz
42-minishell-54d9c42870ba7b7c3380c146d549d9173e68d718.tar.zst
42-minishell-54d9c42870ba7b7c3380c146d549d9173e68d718.zip
ptin de invalid read
Diffstat (limited to 'src/ft_m_loop.c')
-rw-r--r--src/ft_m_loop.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c
index 6a05dd6..7c6259c 100644
--- a/src/ft_m_loop.c
+++ b/src/ft_m_loop.c
@@ -26,8 +26,11 @@ uint8_t
int8_t gnl;
char *prog;
char *buf;
+ char *fin;
- if (!(prog = malloc((quote - line) * sizeof(char))))
+ if (!(prog = ft_calloc(ft_strlen(line + 1), sizeof(char))))
+ return (0);
+ if (!(fin = malloc((ft_strlen(prog) + ft_strlen(buf)) * sizeof(char))))
return (0);
ft_memcpy(prog, line, (quote - line));
buf = ft_strdup(line + (quote - line) + 1);
@@ -39,9 +42,11 @@ uint8_t
ft_sprintf(buf + ft_strlen(buf), "\n%s", line);
}
buf = ft_strtrim(buf, "\"'");
- ft_p_line(ft_strjoin(prog, buf), msh);
+ fin = ft_strjoin(prog, buf);
+ ft_p_line(fin, msh);
ft_memdel((void*)&line);
ft_memdel((void*)&buf);
+ ft_memdel((void*)&fin);
ft_e_lcom(msh);
ft_lcom_clear(&msh->curr);
return (1); /*got second quote, keep going*/