Initialize capacity to 0 when allocating a new cell
authorAlberto Bertogli <albertito@blitiri.com.ar>
Fri, 15 May 2009 02:18:09 +0000 (23:18 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sun, 17 May 2009 21:04:02 +0000 (18:04 -0300)
Otherwise, when later we do cell.capacity == 0 we're using uninitialized
memory and can return the wrong result if we're not lucky enough to get 0s.

gc/gc.d

diff --git a/gc/gc.d b/gc/gc.d
index 3ee81ac0ff34be2c47c07f9e7b355b4ae4c1885d..a7c8f593f545f5657ce7efca7f598311714ec680 100644 (file)
--- a/gc/gc.d
+++ b/gc/gc.d
@@ -533,6 +533,7 @@ public:
 
         // No luck still, allocate new memory
         cell = cast(Cell*) cstdlib.malloc(size + Cell.sizeof);
+        cell.capacity = 0; // so we can later tell it's new
         if (cell)
             goto success;