Fix ft_vec_copy to also copy empty vectors no_crash
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Fri, 19 Sep 2025 06:03:00 +0000 (08:03 +0200)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Fri, 19 Sep 2025 06:03:00 +0000 (08:03 +0200)
ft_arr/ft_vec_copy.c

index 73f6c9771bf12baef6a4ada9b664ee1d17e7a1fb..691aa79526611ce42e338f44a0f3ed47226285a1 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/28 12:02:22 by ljiriste          #+#    #+#             */
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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_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);
 }
 
        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,
 //     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,