Skip to content

Commit

Permalink
Merge pull request #133 from Haliris/err_msg_spaceadd
Browse files Browse the repository at this point in the history
Fixed err message and Leak from orphaned pipe token
  • Loading branch information
Haliris authored Jul 29, 2024
2 parents 443431b + a479745 commit 9782e60
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/built_ins/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/18 10:00:44 by bthomas #+# #+# */
/* Updated: 2024/07/28 14:17:06 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:16:22 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -18,7 +18,7 @@ void call_env(t_data *data, char **command)

if (command[1])
{
ft_putstr_fd("env: '", 2);
ft_putstr_fd("env: \'", 2);
ft_putstr_fd(command[1], 2);
ft_putstr_fd("\': Permission denied.\n", 2);
return ;
Expand Down
4 changes: 3 additions & 1 deletion src/built_ins/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/12 20:32:33 by bthomas #+# #+# */
/* Updated: 2024/07/29 12:05:18 by bthomas ### ########.fr */
/* Updated: 2024/07/29 15:18:38 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,6 +19,8 @@ static bool invalid_key(char *s)
i = 0;
while (s && s[i])
{
if (i == 0 && !ft_isalpha(s[i]))
return (true);
if (invalid_path_char(s[i]))
return (true);
i++;
Expand Down
5 changes: 3 additions & 2 deletions src/execution/execution_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* execution_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: bthomas <bthomas@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/07 18:14:25 by jteissie #+# #+# */
/* Updated: 2024/07/28 17:34:45 by jteissie ### ########.fr */
/* Updated: 2024/07/29 14:18:47 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -24,6 +24,7 @@ void handle_error(char *message, int code, t_data *data, char **cmd)
ft_putstr_fd(cmd[0], STDERR_FILENO);
if (message)
{
ft_putchar_fd(' ', STDERR_FILENO);
ft_putstr_fd(message, STDERR_FILENO);
ft_putchar_fd('\n', STDERR_FILENO);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/lex_bools2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/20 12:36:56 by bthomas #+# #+# */
/* Updated: 2024/07/29 13:41:33 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:12:46 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion src/lexer/lex_retrieve_str_tk.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/25 10:40:12 by bthomas #+# #+# */
/* Updated: 2024/07/29 10:24:50 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:44:11 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
16 changes: 7 additions & 9 deletions src/lexer/lex_token_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 11:46:10 by bthomas #+# #+# */
/* Updated: 2024/07/25 17:45:55 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:56:59 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -25,16 +25,14 @@ t_tokentype get_last_tk_type(t_data *data)
t_token *get_token(t_data *data, char *lexstr, char *path, t_tokentype type)
{
t_token *token;
t_token *last;

if (type == TK_PIPE)
last = lex_get_last_token(data);
if (last && last->type == TK_PIPE && lexstr && *lexstr == '|')
{
if (!data->token)
return (free(lexstr), NULL);
token = data->token;
while (token->next)
token = token->next;
if (token->type == TK_PIPE || token->type == TK_REDIR)
return (free(lexstr), NULL);
free(lexstr);
lexstr = NULL;
return (NULL);
}
token = ft_calloc(1, sizeof(t_token));
if (!token)
Expand Down
6 changes: 3 additions & 3 deletions src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 17:48:06 by bento #+# #+# */
/* Updated: 2024/07/28 16:14:06 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:56:01 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -119,9 +119,9 @@ int lexer(t_data *data)

input_len = ft_strlen(data->input);
if (build_tokenlist1(data, input_len))
return (1);
return (LEXER_ERROR);
if (invalid_tokens(data))
return (1);
return (LEXER_ERROR);
if (build_heredocs(data) == PANIC)
{
unlink_heredocs(data);
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/validate_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 16:48:14 by bthomas #+# #+# */
/* Updated: 2024/07/29 13:41:11 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:41:07 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
5 changes: 3 additions & 2 deletions src/lexer/validate_tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/10 12:26:40 by bthomas #+# #+# */
/* Updated: 2024/07/29 12:00:47 by bthomas ### ########.fr */
/* Updated: 2024/07/29 14:36:25 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -41,7 +41,8 @@ static bool is_orphaned_op(t_token *token)
is_echo = false;
if (token->type == TK_BUILTIN && ft_strcmp("echo", token->lexstr) == 0)
is_echo = true;
if (token->type == TK_PIPE && (!token->prev || !token->next))
if (token->type == TK_PIPE && ((!token->prev || !token->next)
|| token->next->type == TK_PIPE))
return (true);
if (token->type == TK_OPERATOR && !next && !is_echo
&& !in_builtin(token, "export"))
Expand Down

0 comments on commit 9782e60

Please sign in to comment.