From: cuz Date: Sun, 25 Jun 2000 13:17:26 +0000 (+0000) Subject: Fixed a bug X-Git-Tag: V2.12.0~3385 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a992dd05a0ab7de7061361844f25b53fcee610fe;p=cc65 Fixed a bug git-svn-id: svn://svn.cc65.org/cc65/trunk@128 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- 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) - - - - - -