From: Lukas Jiriste Date: Fri, 21 Jun 2024 09:09:49 +0000 (+0200) Subject: Make ft_parse_tree_print handle NULLs gracefully X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=e24b7bb1da4e3cb808984d1439fed23bbf049469;p=Libft.git Make ft_parse_tree_print handle NULLs gracefully --- diff --git a/ft_parse/ft_parse_tree_print.c b/ft_parse/ft_parse_tree_print.c index f8e7885..28ba3c8 100644 --- a/ft_parse/ft_parse_tree_print.c +++ b/ft_parse/ft_parse_tree_print.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/21 09:51:43 by ljiriste #+# #+# */ -/* Updated: 2024/06/21 10:33:09 by ljiriste ### ########.fr */ +/* Updated: 2024/06/21 11:07:45 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,11 @@ static void print_children_at_depth(t_parse_tree_node *node, size_t depth, char { size_t i; + if (!node) + { + ft_printf("%s\n", node); + return ; + } i = 0; while (i + 1 < node->children.size) { @@ -38,6 +43,11 @@ static void print_children_at_depth(t_parse_tree_node *node, size_t depth, char static void print_last_at_depth(t_parse_tree_node *node, size_t depth, char branches[MAX_WIDTH]) { + if (!node) + { + ft_printf("%s\n", node); + return ; + } ft_printf("%s-%s\n", branches, node->token.type); branches[ft_strlen(branches) - 1] = ' '; ft_strlcat(branches, " |", MAX_WIDTH); @@ -46,6 +56,11 @@ static void print_last_at_depth(t_parse_tree_node *node, size_t depth, char bran static void print_node_at_depth(t_parse_tree_node *node, size_t depth, char branches[MAX_WIDTH]) { + if (!node) + { + ft_printf("%s\n", node); + return ; + } if (depth == 0) { ft_printf("%s\n", node->token.type);