OSDN Git Service

POSIX requires that errno be set whenever 0 is returned by malloc()
authorMike Frysinger <vapier@gentoo.org>
Mon, 2 Apr 2007 12:06:00 +0000 (12:06 -0000)
committerMike Frysinger <vapier@gentoo.org>
Mon, 2 Apr 2007 12:06:00 +0000 (12:06 -0000)
libc/stdlib/malloc-simple/alloc.c
libc/stdlib/malloc-standard/malloc.c
libc/stdlib/malloc/malloc.c

index 0b84207..321f319 100644 (file)
@@ -32,7 +32,8 @@ void *malloc(size_t size)
                size++;
 #else
                /* Some programs will call malloc (0).  Lets be strict and return NULL */
-               return 0;
+               __set_errno(ENOMEM);
+               return NULL;
 #endif
        }
 
index 85b5081..3253ebd 100644 (file)
@@ -826,7 +826,10 @@ void* malloc(size_t bytes)
     void *          retval;
 
 #if !defined(__MALLOC_GLIBC_COMPAT__)
-    if (!bytes) return NULL;
+    if (!bytes) {
+        __set_errno(ENOMEM);
+        return NULL;
+    }
 #endif
 
     __MALLOC_LOCK;
index 2ec8b07..373b5dc 100644 (file)
@@ -200,7 +200,7 @@ malloc (size_t size)
 #else
   /* Some programs will call malloc (0).  Lets be strict and return NULL */
   if (unlikely (size == 0))
-    return 0;
+    goto oom;
 #endif
 
   /* Check if they are doing something dumb like malloc(-1) */