Skip to content

Commit f87036d

Browse files
committed
change #9000: fixes after merge
1 parent bdf7ca8 commit f87036d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

include/json/allocator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
#include <cstring>
1010
#include <memory>
11+
#if defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
12+
//We have memset_s from cstring
13+
#else
14+
#include <algorithm>
15+
#endif
1116

1217
#pragma pack(push)
1318
#pragma pack()
@@ -39,7 +44,12 @@ template <typename T> class SecureAllocator {
3944
*/
4045
void deallocate(pointer p, size_type n) {
4146
// memset_s is used because memset may be optimized away by the compiler
47+
#if defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
4248
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
49+
#else
50+
// fallback for systems without memset_s (e.g., most Linux distros)
51+
std::fill_n(p, n, T());
52+
#endif
4353
// free using "global operator delete"
4454
::operator delete(p);
4555
}

include/json/value.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,18 @@ class JSON_API Value {
392392
unsigned getCStringLength() const; //Allows you to understand the length of the CString
393393
template<typename T = JSONCPP_STRING>
394394
T asString() const { ///< Embedded zeroes are possible.
395-
switch (type_) {
395+
switch (type()) {
396396
case nullValue:
397397
return "";
398398
case stringValue:
399399
{
400-
if (value_.string_ == 0) return "";
400+
if (value_.string_ == nullptr)
401+
return "";
401402
unsigned this_len;
402403
char const* this_str;
403-
decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
404-
return T(this_str, this_str + this_len);
404+
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
405+
&this_str);
406+
return T(this_str, this_len);
405407
}
406408
case booleanValue:
407409
return value_.bool_ ? "true" : "false";
@@ -589,9 +591,6 @@ class JSON_API Value {
589591
/// \post type() is unchanged
590592
void removeMember(const char* key);
591593

592-
/// Same as removeMember(JSONCPP_STRING const& key, Value* removed)
593-
bool removeMember(const char* begin, const char* end, Value* removed);
594-
595594
#if JSONCPP_USING_SECURE_MEMORY
596595
/// Same as removeMember(const char*)
597596
/// \param key may contain embedded nulls.
@@ -643,8 +642,6 @@ class JSON_API Value {
643642
/// Return true if the object has a member named key.
644643
/// \note 'key' must be null-terminated.
645644
bool isMember(const char* key) const;
646-
/// Same as isMember(JSONCPP_STRING const& key)const
647-
bool isMember(const char* begin, const char* end) const;
648645
#if JSONCPP_USING_SECURE_MEMORY
649646
/// Return true if the object has a member named key.
650647
/// \param key may contain embedded nulls.

src/lib_json/json_value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static inline char* duplicateStringValue(const char* value, size_t length) {
131131
/* Record the length as a prefix.
132132
*/
133133
#if JSONCPP_USING_SECURE_MEMORY
134-
char* duplicateAndPrefixStringValue(const char* value,
134+
char* Value::duplicateAndPrefixStringValue(const char* value,
135135
unsigned int length) {
136136
#else
137137
static inline char* duplicateAndPrefixStringValue(const char* value,

0 commit comments

Comments
 (0)