In stgReallocForGMP, we need to copy min(old_size,new_size)
authorIan Lynagh <igloo@earth.li>
Thu, 11 Sep 2008 12:08:06 +0000 (12:08 +0000)
committerIan Lynagh <igloo@earth.li>
Thu, 11 Sep 2008 12:08:06 +0000 (12:08 +0000)
We used to always copy old_size

rts/sm/Storage.c

index a6134c6..8d237c1 100644 (file)
@@ -926,12 +926,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;
     }