From 30170d651c108400b1b9ed626ba715a5d95c5fd2 Mon Sep 17 00:00:00 2001 From: Christian Ledergerber Date: Tue, 13 Oct 2020 17:55:58 +0200 Subject: [PATCH] Fix c++20 compilation problem for clang10 and fix potential bug due to compiler optimization --- include/json/allocator.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/json/allocator.h b/include/json/allocator.h index 0f5c224..95ef8a5 100644 --- a/include/json/allocator.h +++ b/include/json/allocator.h @@ -35,11 +35,10 @@ public: * Release memory which was allocated for N items at pointer P. * * The memory block is filled with zeroes before being released. - * The pointer argument is tagged as "volatile" to prevent the - * compiler optimizing out this critical step. */ - void deallocate(volatile pointer p, size_type n) { - std::memset(p, 0, n * sizeof(T)); + void deallocate(pointer p, size_type n) { + // memset_s is used because memset may be optimized away by the compiler + memset_s(p, n * sizeof(T), 0, n * sizeof(T)); // free using "global operator delete" ::operator delete(p); }