]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/realloc.c
Removed unused stuff
[cc65] / libsrc / common / realloc.c
index 32c05f46f8dbac520051accea1e41b6c6077ef4f..c2da6ae73d1d2c1ac2c0a16bdf937a9bf381aedb 100644 (file)
@@ -62,7 +62,19 @@ void* realloc (void* block, size_t size)
      * room left. Try to allocate a new block and copy the data.
      */
     if (newblock = malloc (size)) {
-       memcpy (newblock, block, oldsize - 2);
+
+       /* Adjust the old size to the user visible portion */
+       oldsize -= sizeof (unsigned);
+
+       /* If the new block is larger than the old one, copy the old 
+        * data only 
+        */
+       if (size > oldsize) {
+           size = oldsize;
+       }
+
+       /* Copy the block data */
+       memcpy (newblock, block, size);
        free (block);
     }
     return newblock;
@@ -70,9 +82,3 @@ void* realloc (void* block, size_t size)
 
 
 
-
-
-
-
-
-