File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,12 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
93
93
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin" CACHE PATH "Executable/dll output dir." )
94
94
endif ()
95
95
96
+ include (CheckFunctionExists)
97
+ check_function_exists(memset_s HAVE_MEMSET_S)
98
+ if (HAVE_MEMSET_S)
99
+ add_definitions ("-DHAVE_MEMSET_S=1" )
100
+ endif ()
101
+
96
102
if (JSONCPP_USE_SECURE_MEMORY)
97
103
add_definitions ("-DJSONCPP_USE_SECURE_MEMORY=1" )
98
104
endif ()
Original file line number Diff line number Diff line change 6
6
#ifndef JSON_ALLOCATOR_H_INCLUDED
7
7
#define JSON_ALLOCATOR_H_INCLUDED
8
8
9
+ #include < algorithm>
9
10
#include < cstring>
10
11
#include < memory>
11
12
@@ -38,8 +39,16 @@ template <typename T> class SecureAllocator {
38
39
* The memory block is filled with zeroes before being released.
39
40
*/
40
41
void deallocate (pointer p, size_type n) {
41
- // memset_s is used because memset may be optimized away by the compiler
42
+ // These constructs will not be removed by the compiler during optimization,
43
+ // unlike memset.
44
+ #if defined(HAVE_MEMSET_S)
42
45
memset_s (p, n * sizeof (T), 0 , n * sizeof (T));
46
+ #elif defined(_WIN32)
47
+ RtlSecureZeroMemory (p, n * sizeof (T));
48
+ #else
49
+ std::fill_n (reinterpret_cast <volatile unsigned char *>(p), n, 0 );
50
+ #endif
51
+
43
52
// free using "global operator delete"
44
53
::operator delete (p);
45
54
}
You can’t perform that action at this time.
0 commit comments