redirection parsing: check for null in arguments

This commit is contained in:
Khaïs COLIN 2025-03-10 16:42:53 +01:00
parent d9dfac106d
commit 47ac767f2a
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 13 additions and 4 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 12:30:04 by khais #+# #+# */
/* Updated: 2025/03/11 14:57:56 by khais ### ########.fr */
/* Updated: 2025/03/11 14:58:11 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -71,6 +71,8 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
t_redir_type type;
size_t i;
if (cmd == NULL)
return (NULL);
i = 0;
while (wordlist_get(cmd->words, i) != NULL)
{

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/10 16:38/00 by khais #+# #+# */
/* Updated: 2025/03/10 16:38:00 by khais ### ########.fr */
/* Created: 2025/03/10 16:50/33 by khais #+# #+# */
/* Updated: 2025/03/10 16:50:33 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -97,6 +97,13 @@ static void test_redirection_parsing_output_no_filename_at_end(void)
do_leak_check();
}
static void test_redirection_parsing_null(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
assert(parse_redirections(NULL) == NULL);
do_leak_check();
}
int main(void) {
test_redirection_parsing_no_redirections();
@ -104,6 +111,6 @@ int main(void) {
test_redirection_parsing_output_at_end();
test_redirection_parsing_output_in_middle();
test_redirection_parsing_output_no_filename_at_end();
// check null input
test_redirection_parsing_null();
return (0);
}