diff --git a/Makefile b/Makefile index 084b2ac..c43bc18 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ CFLAGS = -Wall -Wextra $(INCLUDES) -g # add -Werror, del -g VPATH = $(DIR_SRCS) DIR_SRCS = srcs srcs/builtins srcs/lexing \ - srcs/parsing srcs/parsing/valid_syntax srcs/parsing/expansions + srcs/parsing srcs/parsing/valid_syntax \ + srcs/parsing/expansions srcs/parsing/redirections INCLUDES = -I$(HEADERS_D) -I$(LIBFT_D) @@ -30,6 +31,7 @@ SRCS = main.c init.c free.c generic.c \ valid_syntax.c valid_pipeline.c valid_command.c valid_io_redirect.c \ words_expansions.c expand_token.c rejoin_after_expand.c new_token_for_each_field.c \ ft_split_quotes.c ft_strdup_quotes.c \ + redirections.c here_doc.c \ env.c exit.c echo.c DIR_OBJS = builds diff --git a/headers/minishell_prototypes.h b/headers/minishell_prototypes.h index 7cf8fb4..04f2b62 100644 --- a/headers/minishell_prototypes.h +++ b/headers/minishell_prototypes.h @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */ -/* Updated: 2021/11/14 00:35:59 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 10:12:30 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,9 @@ int valid_token(t_token **token_list, enum e_token_id token_id); int valid_command_separator(const t_token *token_list); size_t count_pipes(t_token *token); t_cmd **alloc_cmd_array(size_t cmd_nbr); -int words_expansions(t_token *t); +int words_expansions(t_token *token_list); +int token_expansions(t_token **t); +int redirections(t_token *t, t_cmd **cmd_arr); // Builtins int builtin_env(int argc, char *argv[], t_all *c); @@ -60,5 +62,10 @@ t_list *ft_lstbeforelast(t_list *lst); t_list *ft_lstnew_generic(size_t lst_sizse, size_t content_size); typedef void *(*t_dup_func)(void *); void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *)); +void ft_perror_io(char *err_str, char *io_file); +int ft_reti_perror_io(int ret, char *err_str, char *io_file); + +char **ft_split_quotes(char const *s, char c); +char *ft_strdup_quotes(const char *s); #endif diff --git a/srcs/free.c b/srcs/free.c index 7cbfeba..2e299fd 100644 --- a/srcs/free.c +++ b/srcs/free.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */ -/* Updated: 2021/11/14 04:48:49 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 08:26:32 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ int free_exit(t_all *c, int exit_status) ft_free_cmd_arr(c->cmd_arr); if (c->termios_changed) tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios); + gnl(STDIN_FILENO, NULL, 1); rl_clear_history(); exit(exit_status); } diff --git a/srcs/generic.c b/srcs/generic.c index f9d1839..002eec3 100644 --- a/srcs/generic.c +++ b/srcs/generic.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/08 09:25:35 by lperrey #+# #+# */ -/* Updated: 2021/11/13 04:23:54 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 08:27:40 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -197,3 +197,16 @@ t_list *ft_lstnew_generic(size_t lst_size, size_t content_size) elem->next = NULL; return (elem); } + +void ft_perror_io(char *err_str, char *io_file) +{ + ft_putstr_fd(err_str, 2); + perror(io_file); +} + +int ft_reti_perror_io(int ret, char *err_str, char *io_file) +{ + ft_putstr_fd(err_str, 2); + perror(io_file); + return (ret); +} diff --git a/srcs/parsing/expansions/ft_strdup_quotes.c b/srcs/parsing/expansions/ft_strdup_quotes.c index 465bf1d..1b4525f 100644 --- a/srcs/parsing/expansions/ft_strdup_quotes.c +++ b/srcs/parsing/expansions/ft_strdup_quotes.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/13 04:35:06 by lperrey #+# #+# */ -/* Updated: 2021/11/13 10:18:51 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 06:01:45 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ enum e_in_quote_state }; static int quote_state_change(int *quote_state, const char *s); +/* Duplicate a string minus the quoting characters ['] and ["]*/ char *ft_strdup_quotes(const char *s) { unsigned int i; diff --git a/srcs/parsing/expansions/words_expansions.c b/srcs/parsing/expansions/words_expansions.c index 8c7e356..400e286 100644 --- a/srcs/parsing/expansions/words_expansions.c +++ b/srcs/parsing/expansions/words_expansions.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */ -/* Updated: 2021/11/13 21:27:20 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 10:13:38 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,6 @@ enum e_in_quote_state t_list *ft_lstnew_generic(size_t lst_sizse, size_t content_size); t_list *expand_token(char *content); char *rejoin_after_expand(t_list *expand_lst); -char **ft_split_quotes(char const *s, char c); // Generic -char *ft_strdup_quotes(const char *s); // Generic int new_token_for_each_field(char **fields, t_token **t); // 1 - chaque bout dans un element d'une t_list @@ -35,39 +33,43 @@ int new_token_for_each_field(char **fields, t_token **t); // (ft_lstadd_front() sur le token original, puis set le token orignal à : // t->id = 0 ; free(t->content) ; t->content = NULL ; pour qu'il soit ignoré sur la suite du parsing) -int words_expansions(t_token *t) +int words_expansions(t_token *token_list) { - void *tmp_expand; - char **tmp_split; - - while (t) + while (token_list) { - if (t->id == T_WORD) - { - // 1 - tmp_expand = expand_token(t->content); - if (!tmp_expand) - return (0); - // 2 - tmp_expand = rejoin_after_expand(tmp_expand); - if (!tmp_expand) - return (0); - // 3 - tmp_split = ft_split_quotes(tmp_expand, ' '); - free(tmp_expand); - if (!tmp_split) - return (0); - // 4 - tmp_expand = ft_dup_2d_arr(tmp_split, (t_dup_func)ft_strdup_quotes); - ft_free_2d_arr(tmp_split); - tmp_split = tmp_expand; - if (!tmp_split) - return (0); - // 5 - if (!new_token_for_each_field(tmp_split, &t)) - return (0); - } - t = t->next; + if (token_list->id == T_WORD) + token_expansions(&token_list); + token_list = token_list->next; } return (1); } + +int token_expansions(t_token **t) +{ + void *tmp; + char **tmp_split; + + // 1 + tmp = expand_token((*t)->content); + if (!tmp) + return (0); + // 2 + tmp = rejoin_after_expand(tmp); + if (!tmp) + return (0); + // 3 + tmp_split = ft_split_quotes(tmp, ' '); + free(tmp); + if (!tmp_split) + return (0); + // 4 + tmp = ft_dup_2d_arr(tmp_split, (t_dup_func)ft_strdup_quotes); + ft_free_2d_arr(tmp_split); + tmp_split = tmp; + if (!tmp_split) + return (0); + // 5 + if (!new_token_for_each_field(tmp_split, t)) + return (0); + return (1); +} diff --git a/srcs/parsing/parsing.c b/srcs/parsing/parsing.c index 975b973..0b3da2d 100644 --- a/srcs/parsing/parsing.c +++ b/srcs/parsing/parsing.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */ -/* Updated: 2021/11/14 00:35:42 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 11:00:39 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,8 +69,8 @@ t_cmd **parsing(t_token *token_list) return (NULL); // 2.9.1 - 3) Redirection -/* if (!redirections(token_list, cmd_arr)) - return (ft_retp_free(NULL, cmd_arr, ft_free_cmd_arr)); */ + if (!redirections(token_list, cmd_arr)) + return (ft_retp_free(NULL, cmd_arr, (void(*)(void *))ft_free_cmd_arr)); // Struct CMD fill diff --git a/srcs/parsing/redirections/here_doc.c b/srcs/parsing/redirections/here_doc.c new file mode 100644 index 0000000..2662e92 --- /dev/null +++ b/srcs/parsing/redirections/here_doc.c @@ -0,0 +1,102 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* here_doc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lperrey +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ +/* Updated: 2021/11/14 10:58:37 by lperrey ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +#define TMP_HERE_DOC "/tmp/minishell_here_doc" + +static int here_doc_write(char *delimiter, int doc_fd); + +int here_doc(char *delimiter) +{ + // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04 + // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02 + /* If any part of word is quoted, + the delimiter shall be formed by performing quote removal on word, + and the here-document lines shall not be expanded. + Otherwise, the delimiter shall be the word itself. */ + // TODO : A voir si on fait les expansions de variables dans le here_doc. + // implementer une gestion des signaux pour here_doc (actuellement ça leaks). + // Peut-être remplacer gnl() par readline() pour avoir une gestion correct + // du terminal (actuellement l'affichage lors du changement de ligne est foireux). + int here_doc; + + delimiter = ft_strdup_quotes(delimiter); + if (!delimiter) + return (ft_reti_perror(-1, "ft_strdup_quotes()")); + here_doc = open(TMP_HERE_DOC, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU); + if (here_doc == -1) + return (ft_reti_perror_io(-1, "open() ", TMP_HERE_DOC)); + if (!here_doc_write(delimiter, here_doc)) + { + gnl(STDIN_FILENO, NULL, 1); + return (0); + } + if (close(here_doc) == -1) + ft_perror_io("close() ", TMP_HERE_DOC); + here_doc = open(TMP_HERE_DOC, O_RDONLY); + if (here_doc == -1) + ft_perror_io("open() ", TMP_HERE_DOC); + if (unlink(TMP_HERE_DOC) == -1) + return (ft_reti_perror_io(-1, "unlink() ", TMP_HERE_DOC)); + return (here_doc); +} + +static int here_doc_write(char *delimiter, int doc_fd) +{ + char *line; + + while (1) + { + line = NULL; + if (gnl(STDIN_FILENO, &line, 0) == -1) + return (ft_reti_perror_free(0, line, free, "gnl() STDIN")); + if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois. + break ; + if (write(doc_fd, line, ft_strlen(line)) == -1) + return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC)); + if (write(doc_fd, "\n", 1) == -1) + return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC)); + free(line); + } + free(line); + gnl(STDIN_FILENO, NULL, 1); + return (1); +} + +/* +static int here_doc_write(char *delimiter, int doc_fd) +{ + char *line; + int ret; + + line = NULL; + ret = 1; + while (ret) + { + ret = gnl(STDIN_FILENO, &line, 0); + if (ret == -1) + return (ft_reti_perror_free(0, line, free, "gnl() STDIN")); + if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois. + break ; + if (write(doc_fd, line, ft_strlen(line)) == -1) + return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC)); + if (write(doc_fd, "\n", 1) == -1) + return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC)); + free(line); + line = NULL; + } + free(line); + gnl(STDIN_FILENO, NULL, 1); + return (1); +} + */ diff --git a/srcs/parsing/redirections.c b/srcs/parsing/redirections/redirections.c similarity index 66% rename from srcs/parsing/redirections.c rename to srcs/parsing/redirections/redirections.c index b9fa650..0870bcd 100644 --- a/srcs/parsing/redirections.c +++ b/srcs/parsing/redirections/redirections.c @@ -6,74 +6,16 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ -/* Updated: 2021/11/12 20:17:09 by lperrey ### ########.fr */ +/* Updated: 2021/11/14 10:04:21 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_reti_perror_io(int ret, char *err_str, char *io_file) // generic -{ - ft_putstr_fd(err_str, 2); - perror(io_file); - return (ret); -} +int here_doc(char *delimiter); -int here_doc_handle_PLACEHOLDER(char *delimiter) -{ - // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04 - // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02 - /* If any part of word is quoted, - the delimiter shall be formed by performing quote removal on word, - and the here-document lines shall not be expanded. - Otherwise, the delimiter shall be the word itself. */ - // Pas d'expansion sur le delimiter, mais quote removal tout de même. - // TODO : quote removal sur le delimiter. - QUOTE_REMOVAL_PLACEHOLDER(); -} - -int redirect_cmd_input(t_token *t, t_cmd *cmd) -{ - if (cmd->fd_in != STDIN_FILENO && cmd->fd_in > 0) - if (close(cmd->fd_in) == -1) - perror("close()"); - if (t->id == '<') - { - // TODO : Expansion + quote removal sur le word t->next->content. - // si plus d'un champ ou aucun champ aprés expansion, - // message d'erreur comme bash "bash: $VAR: ambiguous redirect" - // OU prise en compte seulement du premier champ. - EXPAND_AND_QUOTE_REMOVAL_PLACEHOLDER(); - cmd->fd_in = open(t->next->content, O_RDONLY); - if (cmd->fd_in == -1) - ft_reti_perror_io(0, "open() ", t->next->content); - } - else if (t->id == T_DLESS) - cmd->fd_in = here_doc_handle_PLACEHOLDER(t->next->content); // TODO - return (1); -} - -int redirect_cmd_output(t_token *t, t_cmd *cmd) -{ - int flags; - - if (cmd->fd_out != STDOUT_FILENO && cmd->fd_out > 0) - if (close(cmd->fd_out) == -1) - perror("close()"); - // TODO : Expansion + quote removal sur le word t->next->content. - // si plus d'un champ ou aucun champ aprés expansion, - // message d'erreur comme bash "bash: $VAR: ambiguous redirect" - // OU prise en compte seulement du premier champ. - EXPAND_AND_QUOTE_REMOVAL_PLACEHOLDER(); - if (t->id == '>') - flags = O_WRONLY | O_CREAT | O_TRUNC; - else if (t->id == T_DGREAT) - flags = O_WRONLY | O_CREAT | O_APPEND; - cmd->fd_out = open(t->next->content, flags, S_IRWXU); - if (cmd->fd_out == -1) - return (ft_reti_perror_io(0, "open() ", t->next->content)); - return (1); -} +static int redirect_cmd_input(t_token *t, t_cmd *cmd); +static int redirect_cmd_output(t_token *t, t_cmd *cmd); int redirections(t_token *t, t_cmd **cmd_arr) { @@ -98,3 +40,51 @@ int redirections(t_token *t, t_cmd **cmd_arr) } return (1); } + +static int redirect_cmd_input(t_token *t, t_cmd *cmd) +{ + if (cmd->fd_in != STDIN_FILENO && cmd->fd_in > 0) + if (close(cmd->fd_in) == -1) + perror("close()"); + if (t->id == '<') + { + // TODO : Expansion + quote removal sur le word t->next->content. + // si plus d'un champ ou aucun champ aprés expansion, + // message d'erreur comme bash "bash: $VAR: ambiguous redirect" + // OU prise en compte seulement du premier champ. + //EXPAND_AND_QUOTE_REMOVAL_PLACEHOLDER(); + cmd->fd_in = open(t->next->content, O_RDONLY); + if (cmd->fd_in == -1) + ft_perror_io("open() ", t->next->content); + } + else if (t->id == T_DLESS) + { + cmd->fd_in = here_doc(t->next->content); + if (cmd->fd_in == -1) + return (ft_reti_print(0, "minishell: heredoc error\n", 2)); + } + return (1); +} + +static int redirect_cmd_output(t_token *t, t_cmd *cmd) +{ + int flags; + + if (cmd->fd_out != STDOUT_FILENO && cmd->fd_out > 0) + if (close(cmd->fd_out) == -1) + perror("close()"); + // TODO : Expansion + quote removal sur le word t->next->content. + // si plus d'un champ ou aucun champ aprés expansion, + // message d'erreur comme bash "bash: $VAR: ambiguous redirect" + // OU prise en compte seulement du premier champ. + //EXPAND_AND_QUOTE_REMOVAL_PLACEHOLDER(); + flags = O_WRONLY | O_CREAT; + if (t->id == '>') + flags = flags | O_TRUNC; + else if (t->id == T_DGREAT) + flags = flags | O_APPEND; + cmd->fd_out = open(t->next->content, flags, S_IRWXU); + if (cmd->fd_out == -1) + return (ft_reti_perror_io(0, "open() ", t->next->content)); + return (1); +} diff --git a/valgrind_invalid_read_to_fix.txt b/valgrind_invalid_read_to_fix.txt deleted file mode 100644 index a9ee338..0000000 --- a/valgrind_invalid_read_to_fix.txt +++ /dev/null @@ -1,157 +0,0 @@ -lucky@Tour-Lemdows10:/mnt/c/Users/Lucky/Desktop/code/minishell> 3[5;6;35 -TOKENS LIST : ------------ -3[5;6;35 -TOKENS LIST EXPANDED : ------------ -3[5;6;35 -lucky@Tour-Lemdows10:/mnt/c/Users/Lucky/Desktop/code/minishell> [6;34'.6' -TOKENS LIST : ------------ -[6;34'.6' -==2095== Invalid read of size 1 -==2095== at 0x403938: count_word (ft_split_quotes.c:63) -==2095== by 0x403806: ft_split_quotes (ft_split_quotes.c:35) -==2095== by 0x402FC0: words_expansions (words_expansions.c:56) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== Address 0x56d265a is 0 bytes after a block of size 10 alloc'd -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x4048A8: ft_strjoin (ft_strjoin.c:23) -==2095== by 0x40115C: ft_strjoinfree_s1 (generic.c:29) -==2095== by 0x40358F: rejoin_after_expand (rejoin_after_expand.c:29) -==2095== by 0x402F97: words_expansions (words_expansions.c:52) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== Invalid read of size 1 -==2095== at 0x4038D1: count_word (ft_split_quotes.c:57) -==2095== by 0x403806: ft_split_quotes (ft_split_quotes.c:35) -==2095== by 0x402FC0: words_expansions (words_expansions.c:56) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== Address 0x56d265a is 0 bytes after a block of size 10 alloc'd -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x4048A8: ft_strjoin (ft_strjoin.c:23) -==2095== by 0x40115C: ft_strjoinfree_s1 (generic.c:29) -==2095== by 0x40358F: rejoin_after_expand (rejoin_after_expand.c:29) -==2095== by 0x402F97: words_expansions (words_expansions.c:52) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== Invalid read of size 1 -==2095== at 0x403C0F: fill_arr (ft_split_quotes.c:151) -==2095== by 0x403888: ft_split_quotes (ft_split_quotes.c:44) -==2095== by 0x402FC0: words_expansions (words_expansions.c:56) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== Address 0x56d265a is 0 bytes after a block of size 10 alloc'd -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x4048A8: ft_strjoin (ft_strjoin.c:23) -==2095== by 0x40115C: ft_strjoinfree_s1 (generic.c:29) -==2095== by 0x40358F: rejoin_after_expand (rejoin_after_expand.c:29) -==2095== by 0x402F97: words_expansions (words_expansions.c:52) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== Invalid write of size 1 -==2095== at 0x403D30: fill_arr (ft_split_quotes.c:158) -==2095== by 0x403888: ft_split_quotes (ft_split_quotes.c:44) -==2095== by 0x402FC0: words_expansions (words_expansions.c:56) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== Address 0x56d26fa is 0 bytes after a block of size 10 alloc'd -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x404760: ft_calloc (ft_calloc.c:19) -==2095== by 0x403B3C: alloc_words (ft_split_quotes.c:95) -==2095== by 0x403852: ft_split_quotes (ft_split_quotes.c:39) -==2095== by 0x402FC0: words_expansions (words_expansions.c:56) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== Invalid read of size 1 -==2095== at 0x403EE2: ft_strdup_quotes (ft_strdup_quotes.c:36) -==2095== by 0x40149A: ft_dup_2d_arr (generic.c:124) -==2095== by 0x402FFA: words_expansions (words_expansions.c:61) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== Address 0x56d26fa is 0 bytes after a block of size 10 alloc'd -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x404760: ft_calloc (ft_calloc.c:19) -==2095== by 0x403B3C: alloc_words (ft_split_quotes.c:95) -==2095== by 0x403852: ft_split_quotes (ft_split_quotes.c:39) -==2095== by 0x402FC0: words_expansions (words_expansions.c:56) -==2095== by 0x40275E: parsing (parsing.c:80) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -TOKENS LIST EXPANDED : ------------ -[6;34.6 -lucky@Tour-Lemdows10:/mnt/c/Users/Lucky/Desktop/code/minishell> ^D==2095== -==2095== FILE DESCRIPTORS: 3 open at exit. -==2095== Open file descriptor 2: /dev/tty1 -==2095== -==2095== -==2095== Open file descriptor 1: /dev/tty1 -==2095== -==2095== -==2095== Open file descriptor 0: /dev/tty1 -==2095== -==2095== -==2095== -==2095== HEAP SUMMARY: -==2095== in use at exit: 134,842 bytes in 208 blocks -==2095== total heap usage: 557 allocs, 349 frees, 165,633 bytes allocated -==2095== -==2095== 16 bytes in 1 blocks are still reachable in loss record 7 of 46 -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x404760: ft_calloc (ft_calloc.c:19) -==2095== by 0x40284F: alloc_cmd_array (alloc_cmd_array.c:34) -==2095== by 0x4027AB: parsing (parsing.c:87) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== 32 bytes in 1 blocks are still reachable in loss record 10 of 46 -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x404760: ft_calloc (ft_calloc.c:19) -==2095== by 0x4028A3: alloc_cmd_array (alloc_cmd_array.c:40) -==2095== by 0x4027AB: parsing (parsing.c:87) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== 224 bytes in 7 blocks are indirectly lost in loss record 19 of 46 -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x404760: ft_calloc (ft_calloc.c:19) -==2095== by 0x4028A3: alloc_cmd_array (alloc_cmd_array.c:40) -==2095== by 0x4027AB: parsing (parsing.c:87) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== 336 (112 direct, 224 indirect) bytes in 7 blocks are definitely lost in loss record 21 of 46 -==2095== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) -==2095== by 0x404760: ft_calloc (ft_calloc.c:19) -==2095== by 0x40284F: alloc_cmd_array (alloc_cmd_array.c:34) -==2095== by 0x4027AB: parsing (parsing.c:87) -==2095== by 0x401A6E: shell_loop (shell_loop.c:40) -==2095== by 0x400DA0: main (main.c:25) -==2095== -==2095== LEAK SUMMARY: -==2095== definitely lost: 112 bytes in 7 blocks -==2095== indirectly lost: 224 bytes in 7 blocks -==2095== possibly lost: 0 bytes in 0 blocks -==2095== still reachable: 48 bytes in 2 blocks -==2095== suppressed: 134,458 bytes in 192 blocks -==2095== -==2095== For counts of detected and suppressed errors, rerun with: -v -==2095== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0) -➜ minishell git:(master) ✗