mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-08-10 21:47:01 -04:00
Fix deallocate for working on old compiers
This commit is contained in:
parent
69098a18b9
commit
2636159062
@ -103,6 +103,12 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
include(CheckFunctionExists)
|
||||||
|
check_function_exists(memset_s HAVE_MEMSET_S)
|
||||||
|
if(HAVE_MEMSET_S)
|
||||||
|
add_definitions("-DHAVE_MEMSET_S=1")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL")
|
set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL")
|
||||||
|
|
||||||
configure_file("${PROJECT_SOURCE_DIR}/version.in"
|
configure_file("${PROJECT_SOURCE_DIR}/version.in"
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#ifndef JSON_ALLOCATOR_H_INCLUDED
|
#ifndef JSON_ALLOCATOR_H_INCLUDED
|
||||||
#define JSON_ALLOCATOR_H_INCLUDED
|
#define JSON_ALLOCATOR_H_INCLUDED
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -38,8 +39,16 @@ public:
|
|||||||
* The memory block is filled with zeroes before being released.
|
* The memory block is filled with zeroes before being released.
|
||||||
*/
|
*/
|
||||||
void deallocate(pointer p, size_type n) {
|
void deallocate(pointer p, size_type n) {
|
||||||
// memset_s is used because memset may be optimized away by the compiler
|
// These constructs will not be removed by the compiler during optimization,
|
||||||
|
// unlike memset.
|
||||||
|
#if defined(HAVE_MEMSET_S)
|
||||||
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
|
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
RtlSecureZeroMemory(p, n * sizeof(T));
|
||||||
|
#else
|
||||||
|
std::fill_n(reinterpret_cast<volatile unsigned char*>(p), n, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
// free using "global operator delete"
|
// free using "global operator delete"
|
||||||
::operator delete(p);
|
::operator delete(p);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user