summaryrefslogtreecommitdiffstats
path: root/libft/src/ft_nrealloc.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-29 19:18:30 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-29 19:18:30 +0200
commit4ede84d4ab98c75ed8655607fe64c205b79ed986 (patch)
tree6f9d5113400faf13a778de0f09c0203c7939b93f /libft/src/ft_nrealloc.c
parentNorm update (diff)
download42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.gz
42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.bz2
42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.xz
42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.zst
42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.zip
libft norm in progress
Diffstat (limited to 'libft/src/ft_nrealloc.c')
-rw-r--r--libft/src/ft_nrealloc.c13
1 files changed, 8 insertions, 5 deletions
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 <stddef.h>
#include <stdlib.h>
-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);
}