changeset 1851:cfc7046fb176

Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Jun 2018 23:11:58 +0300
parents 3d6917948061
children 219417325036
files tools/lib64gfx.c
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Fri Jun 22 23:10:20 2018 +0300
+++ b/tools/lib64gfx.c	Fri Jun 22 23:11:58 2018 +0300
@@ -176,10 +176,15 @@
 
 int dmC64MemBlockReAlloc(DMC64MemBlock *blk, const size_t size)
 {
+    // Reallocate only if new size is larger
+    if (size <= blk->size)
+        return DMERR_OK;
+
     if ((blk->data = dmRealloc(blk->data, size)) == NULL)
         return DMERR_MALLOC;
 
     dmMemset(blk->data + blk->size, 0, size - blk->size);
+
     blk->size = size;
     return DMERR_OK;
 }