aboutsummaryrefslogtreecommitdiff
path: root/src/parse_cmd.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-08-11 12:15:40 +0200
committerDominik Kaiser2024-08-11 12:15:40 +0200
commitf53acc629b1b3e7f4097eef1e26841ef0b9b24c6 (patch)
treec66db435ce50b68f47de47ec632d767b118112ed /src/parse_cmd.c
parent8cf2aec82f98094d8175c5e5daaaa115f9b64fc2 (diff)
downloadminishell-f53acc629b1b3e7f4097eef1e26841ef0b9b24c6.tar.gz
minishell-f53acc629b1b3e7f4097eef1e26841ef0b9b24c6.zip
Fix parser bugs
Diffstat (limited to 'src/parse_cmd.c')
-rw-r--r--src/parse_cmd.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 068a4c1..eb70f0d 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 14:22:32 by dkaiser ### ########.fr */
+/* Updated: 2024/08/11 12:14:11 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -34,11 +34,8 @@ static char **collect_args(t_token **tokens)
cur = *tokens;
i = 0;
- while (cur != NULL)
- {
- i++;
+ while (cur != NULL && ++i)
cur = cur->next;
- }
result = malloc(sizeof(char *) * (i + 1));
if (result == NULL)
return (free_tokens(*tokens), NULL);
@@ -46,10 +43,11 @@ static char **collect_args(t_token **tokens)
i = 0;
while (cur != NULL && cur->type == STRING_TOKEN)
{
+ if (cur->previous)
+ free_token(cur->previous);
result[i] = cur->content.string;
i++;
cur = cur->next;
- free_token(cur->previous);
}
result[i] = NULL;
return (result);