Setting errno for inappropriate input has been removed as Moulinette
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 6 Sep 2023 11:07:57 +0000 (13:07 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 6 Sep 2023 11:07:57 +0000 (13:07 +0200)
deems functions around errno forbidden.

ft_calloc.c

index a4c55b0207dd5f35a1f607cfc9b3d86be0404077..9976848c292227bd5140ed5c9f8bb16201bc1148 100644 (file)
@@ -6,11 +6,19 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/08/15 11:34:52 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/09/05 18:26:57 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/09/06 13:06:22 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
+/*     This should not be commented as to emulate builtin calloc
+       but errno calls function which is deemed forbidden by Moulinette
 #include <errno.h>
+       if (total_bytes / size != nmemb)
+       {
+               errno = ENOMEM;
+               return (NULL);
+       }
+*/
 #include <stdlib.h>    // for malloc
 #include "libft.h"
 
@@ -23,10 +31,7 @@ void *ft_calloc(size_t nmemb, size_t size)
                return (malloc(0));
        total_bytes = nmemb * size;
        if (total_bytes / size != nmemb)
-       {
-               errno = ENOMEM;
                return (NULL);
-       }
        res = malloc(total_bytes);
        if (res == NULL)
                return (NULL);