From: Lukáš Jiřiště Date: Fri, 19 Sep 2025 06:03:00 +0000 (+0200) Subject: Fix ft_vec_copy to also copy empty vectors X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=refs%2Fheads%2Fno_crash;p=Libft.git Fix ft_vec_copy to also copy empty vectors --- diff --git a/ft_arr/ft_vec_copy.c b/ft_arr/ft_vec_copy.c index 73f6c97..691aa79 100644 --- a/ft_arr/ft_vec_copy.c +++ b/ft_arr/ft_vec_copy.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 12:02:22 by ljiriste #+# #+# */ -/* Updated: 2024/07/05 10:26:54 by ljiriste ### ########.fr */ +/* Updated: 2025/09/19 08:02:44 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,12 @@ static t_arr_stat prepare_for_copy(t_vec *dest, const t_vec *src) res = ft_vec_init(dest, src->el_size); if (res != success) return (res); - res = ft_vec_reserve(dest, src->capacity); + if (src->capacity > 0) + res = ft_vec_reserve(dest, src->capacity); return (res); } -// This function the exact current state of src to dest. +// This function copies the exact current state of src to dest. // copy_el function enables deep copy // free_el function enbales cleaning after itself in a case of error t_arr_stat ft_vec_copy(t_vec *dest, const t_vec *src,