Bläddra i källkod

Don't set errno if for zero SIZE returns.
Code formatting cleanup.

Miles Bader 20 år sedan
förälder
incheckning
0a8bcf917a
1 ändrade filer med 14 tillägg och 11 borttagningar
  1. 14 11
      libc/stdlib/malloc/malloc.c

+ 14 - 11
libc/stdlib/malloc/malloc.c

@@ -186,23 +186,26 @@ malloc (size_t size)
     __heap_check (&__malloc_heap, "malloc");
 #endif
 
-#if defined(__MALLOC_GLIBC_COMPAT__)
-  if (unlikely(size == 0))
-      size++;
+#ifdef __MALLOC_GLIBC_COMPAT__
+  if (unlikely (size == 0))
+    size++;
 #else
   /* Some programs will call malloc (0).  Lets be strict and return NULL */
-  if (unlikely(size == 0))
-      goto oom;
+  if (unlikely (size == 0))
+    return 0;
 #endif
+
   /* Check if they are doing something dumb like malloc(-1) */
   if (unlikely(((unsigned long)size > (unsigned long)(MALLOC_HEADER_SIZE*-2))))
-      goto oom;
+    goto oom;
 
   mem = malloc_from_heap (size, &__malloc_heap);
-  if (unlikely(!mem)) {
-oom:
-      __set_errno(ENOMEM);
-      return NULL;
-  }
+  if (unlikely (!mem))
+    {
+    oom:
+      __set_errno (ENOMEM);
+      return 0;
+    }
+
   return mem;
 }