From: Lukáš Jiřiště Date: Sun, 17 Aug 2025 10:32:11 +0000 (+0200) Subject: Fix order of execution not to misuse va_arg X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=afad394321e07d175dfb1bd25e339a462cae69bf;p=Libft.git Fix order of execution not to misuse va_arg The index should not even load at depth 0. --- diff --git a/ft_parse/ft_get_child_deep.c b/ft_parse/ft_get_child_deep.c index d2adcbc..e32d9ec 100644 --- a/ft_parse/ft_get_child_deep.c +++ b/ft_parse/ft_get_child_deep.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/13 21:01:34 by ljiriste #+# #+# */ -/* Updated: 2025/08/13 21:45:10 by ljiriste ### ########.fr */ +/* Updated: 2025/08/17 12:37:48 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,11 @@ t_parse_tree_node *ft_vget_child_deep( { int index; + if (!node || depth == 0) + return (node); index = va_arg(*args, int); if (index < 0) return (NULL); - if (!node || depth == 0) - return (node); return (ft_vget_child_deep(ft_get_node_child(node, (size_t)index), depth - 1, args)); } @@ -45,11 +45,11 @@ const t_parse_tree_node *ft_vcget_child_deep( { int index; + if (!node || depth == 0) + return (node); index = va_arg(*args, int); if (index < 0) return (NULL); - if (!node || depth == 0) - return (node); return (ft_vcget_child_deep(ft_cget_node_child(node, (size_t)index), depth - 1, args)); }