From 4ede84d4ab98c75ed8655607fe64c205b79ed986 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 29 Sep 2020 19:18:30 +0200 Subject: libft norm in progress --- libft/src/ft_nrealloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'libft/src/ft_nrealloc.c') diff --git a/libft/src/ft_nrealloc.c b/libft/src/ft_nrealloc.c index 7369b42..a949def 100644 --- a/libft/src/ft_nrealloc.c +++ b/libft/src/ft_nrealloc.c @@ -14,25 +14,28 @@ #include #include -void - *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize) +void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize) { void *nptr; - if (ptr == NULL) + if (ptr == NULL && newsize > 0) { if ((ptr = malloc(newsize)) == NULL) + { return (NULL); + } return (ptr); } - else if (!newsize) + else if (newsize == 0) { ft_memdel((void*)&ptr); return (NULL); } if ((nptr = malloc(newsize)) == NULL) + { return (ptr); - ft_memcpy(nptr, ptr, oldsize); + } + (void)ft_memcpy(nptr, ptr, oldsize); ft_memdel((void*)&ptr); return (nptr); } -- cgit v1.2.3