]> git.llucax.com Git - software/dgc/naive.git/blobdiff - gc/gc.d
Make calloc() handle null as a malloc() result
[software/dgc/naive.git] / gc / gc.d
diff --git a/gc/gc.d b/gc/gc.d
index a7c8f593f545f5657ce7efca7f598311714ec680..f0471debcd85c0762bb66736aee1d41a0cb465e2 100644 (file)
--- a/gc/gc.d
+++ b/gc/gc.d
@@ -559,11 +559,12 @@ public:
      */
     void* calloc(size_t size, uint attr=0)
     {
+        if (size == 0)
+            return null;
+
         void* ptr = this.malloc(size, attr);
 
-        if (ptr is null)
-            onOutOfMemoryError();
-        else
+        if (ptr !is null) // in case onOutOfMemoryError didn't throw
             cstring.memset(ptr, 0, size);
 
         return ptr;