summaryrefslogtreecommitdiffstats
path: root/libft/src/ft_nrealloc.c
diff options
context:
space:
mode:
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);
}