Replace ASSERT with WARN, and explain why
[ghc-hetmet.git] / rts / sm / Storage.c
index a6134c6..e10304c 100644 (file)
@@ -661,8 +661,8 @@ allocatedBytes( void )
     return allocated;
 }
 
-// split N blocks off the start of the given bdescr, returning the 
-// remainder as a new block group.  We treat the remainder as if it
+// split N blocks off the front of the given bdescr, returning the
+// new block group.  We treat the remainder as if it
 // had been freshly allocated in generation 0.
 bdescr *
 splitLargeBlock (bdescr *bd, nat blocks)
@@ -680,6 +680,7 @@ splitLargeBlock (bdescr *bd, nat blocks)
     new_bd->step    = g0s0;
     new_bd->flags   = BF_LARGE;
     new_bd->free    = bd->free;
+    ASSERT(new_bd->free <= new_bd->start + new_bd->blocks * BLOCK_SIZE_W);
 
     // add the new number of blocks to the counter.  Due to the gaps
     // for block descriptor, new_bd->blocks + bd->blocks might not be
@@ -687,7 +688,7 @@ splitLargeBlock (bdescr *bd, nat blocks)
     bd->step->n_large_blocks += bd->blocks;
 
     return new_bd;
-}    
+}
 
 /* -----------------------------------------------------------------------------
    allocateLocal()
@@ -926,12 +927,14 @@ stgAllocForGMP (size_t size_in_bytes)
 static void *
 stgReallocForGMP (void *ptr, size_t old_size, size_t new_size)
 {
+    size_t min_size;
     void *new_stuff_ptr = stgAllocForGMP(new_size);
     nat i = 0;
     char *p = (char *) ptr;
     char *q = (char *) new_stuff_ptr;
 
-    for (; i < old_size; i++, p++, q++) {
+    min_size = old_size < new_size ? old_size : new_size;
+    for (; i < min_size; i++, p++, q++) {
        *q = *p;
     }