🔨」 fix: Fixed __to_token invalid read if no space

This commit is contained in:
2024-05-28 16:29:34 +02:00
parent c87d45e584
commit ad01524c36
2 changed files with 7 additions and 7 deletions

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 21:05:04 by adjoly #+# #+# */ /* Created: 2024/05/20 21:05:04 by adjoly #+# #+# */
/* Updated: 2024/05/26 17:39:37 by adjoly ### ########.fr */ /* Updated: 2024/05/28 16:28:24 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "tokenizer.h" #include "tokenizer.h"
#include "libft.h"
#include "parsing.h" #include "parsing.h"
size_t __get_sizeof_redir(char *redir_s, t_redirection *redir) size_t __get_sizeof_redir(char *redir_s, t_redirection *redir)
@ -29,9 +30,7 @@ size_t __get_sizeof_redir(char *redir_s, t_redirection *redir)
if (!redir->file_name) if (!redir->file_name)
return (i); return (i);
tmp = redir_s; tmp = redir_s;
if (!i) while (*++tmp && *tmp == ' ')
i++;
if (*tmp && *tmp == ' ')
i++; i++;
i += ft_strlen(redir->file_name); i += ft_strlen(redir->file_name);
return (i); return (i);
@ -44,7 +43,7 @@ t_token *__to_token(char *cmd)
char *tmp; char *tmp;
token = ft_calloc(sizeof(t_token), 1); token = ft_calloc(sizeof(t_token), 1);
token->argv = ft_calloc(sizeof(t_token), 1); token->argv = NULL;
tmp = cmd; tmp = cmd;
while (*tmp) while (*tmp)
{ {
@ -55,7 +54,7 @@ t_token *__to_token(char *cmd)
tmp += __get_sizeof_redir(tmp, tmp_redir); tmp += __get_sizeof_redir(tmp, tmp_redir);
} }
else else
token->argv = ft_strjoin(token->argv, ft_substr(tmp, 0, 1)); token->argv = ft_strjoin_free(token->argv, ft_substr(tmp, 0, 1));
tmp++; tmp++;
} }
return (token); return (token);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */ /* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */
/* Updated: 2024/05/26 17:59:27 by adjoly ### ########.fr */ /* Updated: 2024/05/28 14:25:18 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,5 +26,6 @@ t_list *tokenizer(char *readline)
ft_lstadd_back(&token, ft_lstnew((void*)__to_token(tmp->content))); ft_lstadd_back(&token, ft_lstnew((void*)__to_token(tmp->content)));
tmp = tmp->next; tmp = tmp->next;
} }
ft_lstclear(&piped, free);
return (token); return (token);
} }