aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-09-17 14:39:04 +0200
committerDominik Kaiser2024-09-17 14:39:04 +0200
commit2a3c0b5dd78c7305ef154c2579225dba81813ad2 (patch)
treeffaa5fd5a12a908ae9c86b2caba5a4c53972cdf8 /src/parser.c
parent60adeb49de9458b4e2af0abd1c7b256da0950bc3 (diff)
downloadminishell-2a3c0b5dd78c7305ef154c2579225dba81813ad2.tar.gz
minishell-2a3c0b5dd78c7305ef154c2579225dba81813ad2.zip
Fix pipe parsing error
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/parser.c b/src/parser.c
index f9484c9..4ad514d 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -6,11 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 15:53:29 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 13:48:09 by dkaiser ### ########.fr */
+/* Updated: 2024/09/17 14:35:13 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
+#include "token.h"
static t_token *find_token_by_type(t_token *tokens, int type);
t_token *split_at_first(t_token **tokens, int type);
@@ -49,7 +50,12 @@ static t_node *parse_statement(t_token *tokens)
t_token *left_side_tokens;
left_side_tokens = split_at_first(&tokens, PIPE_TOKEN);
- if (tokens != NULL)
+ if (left_side_tokens == NULL)
+ {
+ free_tokens(tokens);
+ return (NULL);
+ }
+ else if (tokens != NULL)
{
return (new_pipe_node(parse_cmd(left_side_tokens),
parse_statement(tokens)));
@@ -74,6 +80,8 @@ t_token *split_at_first(t_token **tokens, int type)
}
result = *tokens;
*tokens = split->next;
+ if (result == split)
+ result = NULL;
free_token(split);
return (result);
}