From 3bc577004ad0ad348f69e8926244d2b9d69b1863 Mon Sep 17 00:00:00 2001 From: daanx Date: Fri, 21 Apr 2023 09:37:25 -0700 Subject: [PATCH] clarify return codes of VirtualAlloc (issue #731) --- src/prim/windows/prim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/prim/windows/prim.c b/src/prim/windows/prim.c index 1544c641..61532737 100644 --- a/src/prim/windows/prim.c +++ b/src/prim/windows/prim.c @@ -261,7 +261,7 @@ int _mi_prim_alloc(size_t size, size_t try_alignment, bool commit, bool allow_la int _mi_prim_commit(void* addr, size_t size) { void* p = VirtualAlloc(addr, size, MEM_COMMIT, PAGE_READWRITE); - return (p == addr ? 0 : (int)GetLastError()); + return (p != NULL ? 0 : (int)GetLastError()); } int _mi_prim_decommit(void* addr, size_t size, bool* needs_recommit) { @@ -274,11 +274,11 @@ int _mi_prim_reset(void* addr, size_t size) { void* p = VirtualAlloc(addr, size, MEM_RESET, PAGE_READWRITE); mi_assert_internal(p == addr); #if 1 - if (p == addr && addr != NULL) { + if (p != NULL) { VirtualUnlock(addr,size); // VirtualUnlock after MEM_RESET removes the memory from the working set } #endif - return (p == addr ? 0 : (int)GetLastError()); + return (p != NULL ? 0 : (int)GetLastError()); } int _mi_prim_protect(void* addr, size_t size, bool protect) {