From e0017ac105175acb4e06d3144f613615b40b4b88 Mon Sep 17 00:00:00 2001 From: Simon Lindholm Date: Wed, 29 Jun 2022 15:18:29 +0200 Subject: [PATCH] fix realloc zeroing --- kernel32.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel32.cpp b/kernel32.cpp index 3fc030f..cb38c59 100644 --- a/kernel32.cpp +++ b/kernel32.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace kernel32 { uint32_t WIN_FUNC GetLastError() { @@ -42,7 +43,7 @@ namespace kernel32 { lpProcessInformation ); printf("Cannot handle process creation, aborting\n"); - abort(); + exit(1); return 0; } @@ -121,7 +122,7 @@ namespace kernel32 { void *buffer = malloc(dwBytes); if (buffer && (uFlags & 0x40)) { // GMEM_ZEROINT - memset(buffer, 0, dwBytes); + memset(buffer, 0, malloc_usable_size(buffer)); } return buffer; } @@ -137,10 +138,11 @@ namespace kernel32 { } else { if (dwBytes == 0) dwBytes = 1; + size_t oldSize = malloc_usable_size(hMem); void *buffer = realloc(hMem, dwBytes); - if (buffer && (uFlags & 0x40)) { + if (buffer && (uFlags & 0x40) && dwBytes > oldSize) { // GMEM_ZEROINT - memset(buffer, 0, dwBytes); + memset((char*)buffer + oldSize, 0, malloc_usable_size(buffer) - oldSize); } return buffer; }