Skip to content

Commit c631bc5

Browse files
author
Petr Helebrant
committed
improved calloc
1 parent 8e09da1 commit c631bc5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ft_calloc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: phelebra <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/10 17:07:51 by phelebra #+# #+# */
9-
/* Updated: 2023/01/16 14:08:32 by phelebra ### ########.fr */
9+
/* Updated: 2023/01/17 17:48:20 by phelebra ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -16,6 +16,11 @@ void *ft_calloc(size_t nmemb, size_t size)
1616
{
1717
void *ptr;
1818

19+
if (nmemb == 0 || size == 0)
20+
{
21+
ptr = malloc(0);
22+
return (ptr);
23+
}
1924
if ((nmemb * size) < nmemb || (nmemb * size) < size)
2025
return (NULL);
2126
ptr = malloc(nmemb * size);

0 commit comments

Comments
 (0)