]> git.llucax.com Git - software/dgc/naive.git/commitdiff
Make calloc() handle null as a malloc() result
authorLeandro Lucarella <llucax@gmail.com>
Sun, 30 Aug 2009 19:29:00 +0000 (16:29 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sun, 6 Sep 2009 19:27:31 +0000 (16:27 -0300)
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;