From a992dd05a0ab7de7061361844f25b53fcee610fe Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 25 Jun 2000 13:17:26 +0000 Subject: [PATCH] Fixed a bug git-svn-id: svn://svn.cc65.org/cc65/trunk@128 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/realloc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libsrc/common/realloc.c b/libsrc/common/realloc.c index 32c05f46f..c2da6ae73 100644 --- a/libsrc/common/realloc.c +++ b/libsrc/common/realloc.c @@ -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) - - - - - - -- 2.39.5