From 121bfb393982f7ef9ea637fe4f7104e1be85c3bd Mon Sep 17 00:00:00 2001 From: Simon Lindholm Date: Wed, 29 Jun 2022 15:24:58 +0200 Subject: [PATCH] Better realloc zeroing --- kernel32.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel32.cpp b/kernel32.cpp index 52a8daf..db24512 100644 --- a/kernel32.cpp +++ b/kernel32.cpp @@ -140,9 +140,10 @@ namespace kernel32 { dwBytes = 1; size_t oldSize = malloc_usable_size(hMem); void *buffer = realloc(hMem, dwBytes); - if (buffer && (uFlags & 0x40) && dwBytes > oldSize) { + size_t newSize = malloc_usable_size(buffer); + if (buffer && (uFlags & 0x40) && newSize > oldSize) { // GMEM_ZEROINT - memset((char*)buffer + oldSize, 0, malloc_usable_size(buffer) - oldSize); + memset((char*)buffer + oldSize, 0, newSize - oldSize); } return buffer; }