Skip to content

Commit 06d95c6

Browse files
committed
Merge remote-tracking branch 'origin/master' into secure_allocator_clean
Manually re-patched the conflicts Conflicts: include/json/writer.h src/lib_json/json_reader.cpp src/lib_json/json_value.cpp src/lib_json/json_writer.cpp
2 parents 30d4cf0 + 2968ced commit 06d95c6

24 files changed

+1032
-1005
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ CTestTestFile.cmake
3939
cmake_install.cmake
4040
pkg-config/jsoncpp.pc
4141
jsoncpp_lib_static.dir/
42+
43+
# In case someone runs cmake in the root-dir:
44+
/CMakeCache.txt
45+
/Makefile
46+
/include/Makefile
47+
/src/Makefile
48+
/src/jsontestrunner/Makefile
49+
/src/jsontestrunner/jsontestrunner_exe
50+
/src/lib_json/Makefile
51+
/src/test_lib_json/Makefile
52+
/src/test_lib_json/jsoncpp_test

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ENDMACRO()
6464
#SET( JSONCPP_VERSION_MAJOR X )
6565
#SET( JSONCPP_VERSION_MINOR Y )
6666
#SET( JSONCPP_VERSION_PATCH Z )
67-
SET( JSONCPP_VERSION 1.6.5 )
67+
SET( JSONCPP_VERSION 1.7.0 )
6868
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
6969
#IF(NOT JSONCPP_VERSION_FOUND)
7070
# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
@@ -103,10 +103,10 @@ endif()
103103

104104
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
105105
# using regular Clang or AppleClang
106-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion")
106+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion -Werror=conversion")
107107
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
108108
# using GCC
109-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra")
109+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -Werror=conversion")
110110
# not yet ready for -Wsign-conversion
111111

112112
if (JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)

devtools/agent_vmw7.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
{
2-
"cmake_variants" : [
3-
{"name": "generator",
4-
"generators": [
5-
{"generator": [
6-
"Visual Studio 7 .NET 2003",
7-
"Visual Studio 9 2008",
8-
"Visual Studio 9 2008 Win64",
9-
"Visual Studio 10",
10-
"Visual Studio 10 Win64",
11-
"Visual Studio 11",
12-
"Visual Studio 11 Win64"
13-
]
14-
},
15-
{"generator": ["MinGW Makefiles"],
16-
"env_prepend": [{"path": "c:/wut/prg/MinGW/bin"}]
17-
}
18-
]
19-
},
20-
{"name": "shared_dll",
21-
"variables": [
22-
["BUILD_SHARED_LIBS=true"],
23-
["BUILD_SHARED_LIBS=false"]
24-
]
25-
},
26-
{"name": "build_type",
27-
"build_types": [
28-
"debug",
29-
"release"
30-
]
31-
}
32-
]
33-
}
1+
{
2+
"cmake_variants" : [
3+
{"name": "generator",
4+
"generators": [
5+
{"generator": [
6+
"Visual Studio 7 .NET 2003",
7+
"Visual Studio 9 2008",
8+
"Visual Studio 9 2008 Win64",
9+
"Visual Studio 10",
10+
"Visual Studio 10 Win64",
11+
"Visual Studio 11",
12+
"Visual Studio 11 Win64"
13+
]
14+
},
15+
{"generator": ["MinGW Makefiles"],
16+
"env_prepend": [{"path": "c:/wut/prg/MinGW/bin"}]
17+
}
18+
]
19+
},
20+
{"name": "shared_dll",
21+
"variables": [
22+
["BUILD_SHARED_LIBS=true"],
23+
["BUILD_SHARED_LIBS=false"]
24+
]
25+
},
26+
{"name": "build_type",
27+
"build_types": [
28+
"debug",
29+
"release"
30+
]
31+
}
32+
]
33+
}

devtools/agent_vmxp.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
{
2-
"cmake_variants" : [
3-
{"name": "generator",
4-
"generators": [
5-
{"generator": [
6-
"Visual Studio 6",
7-
"Visual Studio 7",
8-
"Visual Studio 8 2005"
9-
]
10-
}
11-
]
12-
},
13-
{"name": "shared_dll",
14-
"variables": [
15-
["BUILD_SHARED_LIBS=true"],
16-
["BUILD_SHARED_LIBS=false"]
17-
]
18-
},
19-
{"name": "build_type",
20-
"build_types": [
21-
"debug",
22-
"release"
23-
]
24-
}
25-
]
26-
}
1+
{
2+
"cmake_variants" : [
3+
{"name": "generator",
4+
"generators": [
5+
{"generator": [
6+
"Visual Studio 6",
7+
"Visual Studio 7",
8+
"Visual Studio 8 2005"
9+
]
10+
}
11+
]
12+
},
13+
{"name": "shared_dll",
14+
"variables": [
15+
["BUILD_SHARED_LIBS=true"],
16+
["BUILD_SHARED_LIBS=false"]
17+
]
18+
},
19+
{"name": "build_type",
20+
"build_types": [
21+
"debug",
22+
"release"
23+
]
24+
}
25+
]
26+
}

include/json/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#ifndef JSON_CONFIG_H_INCLUDED
77
#define JSON_CONFIG_H_INCLUDED
8+
#include <stddef.h>
89

910
/// If defined, indicates that json library is embedded in CppTL library.
1011
//# define JSON_IN_CPPTL 1

include/json/reader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class JSON_API Reader {
4545
*
4646
*/
4747
struct StructuredError {
48-
size_t offset_start;
49-
size_t offset_limit;
48+
ptrdiff_t offset_start;
49+
ptrdiff_t offset_limit;
5050
std::string message;
5151
};
5252

include/json/reader.inl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
#elif defined(__ANDROID__) || defined(__QNXNTO__)
3434
#define snprintf snprintf
3535
#elif __cplusplus >= 201103L
36+
#if !defined(__MINGW32__)
3637
#define snprintf std::snprintf
3738
#endif
39+
#endif
3840

3941
#if defined(__QNXNTO__)
4042
#define sscanf std::sscanf
@@ -361,7 +363,7 @@ bool Reader<_Value>::readComment() {
361363
template<class _Value>
362364
static typename _Value::String normalizeEOL(typename Reader<_Value>::Location begin, typename Reader<_Value>::Location end) {
363365
typename _Value::String normalized;
364-
normalized.reserve(end - begin);
366+
normalized.reserve(static_cast<size_t>(end - begin));
365367
typename Reader<_Value>::Location current = begin;
366368
while (current != end) {
367369
char c = *current++;
@@ -580,7 +582,7 @@ bool Reader<_Value>::decodeNumber(Token& token, _Value& decoded) {
580582
Char c = *current++;
581583
if (c < '0' || c > '9')
582584
return decodeDouble(token, decoded);
583-
typename _Value::UInt digit(c - '0');
585+
typename _Value::UInt digit(static_cast<typename _Value::UInt>(c - '0'));
584586
if (value >= threshold) {
585587
// We've hit or exceeded the max value divided by 10 (rounded down). If
586588
// a) we've only just touched the limit, b) this is the last digit, and
@@ -642,7 +644,7 @@ bool Reader<_Value>::decodeString(Token& token) {
642644

643645
template<class _Value>
644646
bool Reader<_Value>::decodeString(Token& token, String& decoded) {
645-
decoded.reserve(token.end_ - token.start_ - 2);
647+
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
646648
Location current = token.start_ + 1; // skip '"'
647649
Location end = token.end_ - 1; // do not include '"'
648650
while (current != end) {
@@ -728,13 +730,13 @@ template<class _Value>
728730
bool Reader<_Value>::decodeUnicodeEscapeSequence(Token& token,
729731
Location& current,
730732
Location end,
731-
unsigned int& unicode) {
733+
unsigned int& ret_unicode) {
732734
if (end - current < 4)
733735
return addError(
734736
"Bad unicode escape sequence in string: four digits expected.",
735737
token,
736738
current);
737-
unicode = 0;
739+
int unicode = 0;
738740
for (int index = 0; index < 4; ++index) {
739741
Char c = *current++;
740742
unicode *= 16;
@@ -750,6 +752,7 @@ bool Reader<_Value>::decodeUnicodeEscapeSequence(Token& token,
750752
token,
751753
current);
752754
}
755+
ret_unicode = unicode;
753756
return true;
754757
}
755758

@@ -766,7 +769,7 @@ Reader<_Value>::addError(const std::string& message, Token& token, Location extr
766769

767770
template<class _Value>
768771
bool Reader<_Value>::recoverFromError(TokenType skipUntilToken) {
769-
int errorCount = int(errors_.size());
772+
size_t errorCount = errors_.size();
770773
Token skip;
771774
for (;;) {
772775
if (!readToken(skip))
@@ -870,7 +873,7 @@ std::vector<typename Reader<_Value>::StructuredError> Reader<_Value>::getStructu
870873

871874
template<class _Value>
872875
bool Reader<_Value>::pushError(const _Value& value, const std::string& message) {
873-
size_t length = end_ - begin_;
876+
ptrdiff_t const length = end_ - begin_;
874877
if(value.getOffsetStart() > length
875878
|| value.getOffsetLimit() > length)
876879
return false;
@@ -936,8 +939,8 @@ public:
936939
typedef char Char;
937940
typedef const Char* Location;
938941
struct StructuredError {
939-
size_t offset_start;
940-
size_t offset_limit;
942+
ptrdiff_t offset_start;
943+
ptrdiff_t offset_limit;
941944
std::string message;
942945
};
943946

@@ -1634,12 +1637,13 @@ bool OurReader<_Value>::decodeDouble(Token& token, _Value& decoded) {
16341637
double value = 0;
16351638
const int bufferSize = 32;
16361639
int count;
1637-
int length = int(token.end_ - token.start_);
1640+
ptrdiff_t const length = token.end_ - token.start_;
16381641

16391642
// Sanity check to avoid buffer overflow exploits.
16401643
if (length < 0) {
16411644
return addError("Unable to parse token length", token);
16421645
}
1646+
size_t const ulength = static_cast<size_t>(length);
16431647

16441648
// Avoid using a string constant for the format control string given to
16451649
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
@@ -1650,7 +1654,7 @@ bool OurReader<_Value>::decodeDouble(Token& token, _Value& decoded) {
16501654

16511655
if (length <= bufferSize) {
16521656
Char buffer[bufferSize + 1];
1653-
memcpy(buffer, token.start_, length);
1657+
memcpy(buffer, token.start_, ulength);
16541658
buffer[length] = 0;
16551659
count = sscanf(buffer, format, &value);
16561660
} else {
@@ -1680,7 +1684,7 @@ bool OurReader<_Value>::decodeString(Token& token) {
16801684

16811685
template<class _Value>
16821686
bool OurReader<_Value>::decodeString(Token& token, std::string& decoded) {
1683-
decoded.reserve(token.end_ - token.start_ - 2);
1687+
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
16841688
Location current = token.start_ + 1; // skip '"'
16851689
Location end = token.end_ - 1; // do not include '"'
16861690
while (current != end) {
@@ -1766,13 +1770,13 @@ template<class _Value>
17661770
bool OurReader<_Value>::decodeUnicodeEscapeSequence(Token& token,
17671771
Location& current,
17681772
Location end,
1769-
unsigned int& unicode) {
1773+
unsigned int& ret_unicode) {
17701774
if (end - current < 4)
17711775
return addError(
17721776
"Bad unicode escape sequence in string: four digits expected.",
17731777
token,
17741778
current);
1775-
unicode = 0;
1779+
int unicode = 0;
17761780
for (int index = 0; index < 4; ++index) {
17771781
Char c = *current++;
17781782
unicode *= 16;
@@ -1788,6 +1792,7 @@ bool OurReader<_Value>::decodeUnicodeEscapeSequence(Token& token,
17881792
token,
17891793
current);
17901794
}
1795+
ret_unicode = static_cast<unsigned int>(unicode);
17911796
return true;
17921797
}
17931798

@@ -1804,7 +1809,7 @@ OurReader<_Value>::addError(const std::string& message, Token& token, Location e
18041809

18051810
template<class _Value>
18061811
bool OurReader<_Value>::recoverFromError(TokenType skipUntilToken) {
1807-
int errorCount = int(errors_.size());
1812+
size_t errorCount = size_t(errors_.size());
18081813
Token skip;
18091814
for (;;) {
18101815
if (!readToken(skip))
@@ -1902,7 +1907,7 @@ std::vector<typename OurReader<_Value>::StructuredError> OurReader<_Value>::getS
19021907

19031908
template<class _Value>
19041909
bool OurReader<_Value>::pushError(const _Value& value, const std::string& message) {
1905-
size_t length = end_ - begin_;
1910+
ptrdiff_t length = end_ - begin_;
19061911
if(value.getOffsetStart() > length
19071912
|| value.getOffsetLimit() > length)
19081913
return false;

include/json/value.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,10 @@ Json::Value obj_value(Json::objectValue); // {}
592592

593593
// Accessors for the [start, limit) range of bytes within the JSON text from
594594
// which this value was parsed, if any.
595-
void setOffsetStart(size_t start);
596-
void setOffsetLimit(size_t limit);
597-
size_t getOffsetStart() const;
598-
size_t getOffsetLimit() const;
595+
void setOffsetStart(ptrdiff_t start);
596+
void setOffsetLimit(ptrdiff_t limit);
597+
ptrdiff_t getOffsetStart() const;
598+
ptrdiff_t getOffsetLimit() const;
599599

600600
private:
601601
void initBasic(ValueType type, bool allocated = false);
@@ -636,8 +636,8 @@ Json::Value obj_value(Json::objectValue); // {}
636636

637637
// [start, limit) byte offsets in the source JSON text from which this Value
638638
// was extracted.
639-
size_t start_;
640-
size_t limit_;
639+
ptrdiff_t start_;
640+
ptrdiff_t limit_;
641641
};
642642

643643
/** \brief Experimental and untested: represents an element of the "path" to

include/json/value.inl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ const LargestUInt Value<T, U>::maxLargestUInt = LargestUInt(-1);
7070
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
7171
template <typename T, typename U>
7272
static inline bool InRange(double d, T min, U max) {
73+
// The casts can lose precision, but we are looking only for
74+
// an approximate range. Might fail on edge cases though. ~cdunn
75+
//return d >= static_cast<double>(min) && d <= static_cast<double>(max);
7376
return d >= min && d <= max;
7477
}
7578
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
@@ -1448,16 +1451,16 @@ _String Value<_Alloc, _String>::getComment(CommentPlacement placement) const {
14481451
}
14491452

14501453
template<class _Alloc, class _String>
1451-
void Value<_Alloc, _String>::setOffsetStart(size_t start) { start_ = start; }
1454+
void Value<_Alloc, _String>::setOffsetStart(ptrdiff_t start) { start_ = start; }
14521455

14531456
template<class _Alloc, class _String>
1454-
void Value<_Alloc, _String>::setOffsetLimit(size_t limit) { limit_ = limit; }
1457+
void Value<_Alloc, _String>::setOffsetLimit(ptrdiff_t limit) { limit_ = limit; }
14551458

14561459
template<class _Alloc, class _String>
1457-
size_t Value<_Alloc, _String>::getOffsetStart() const { return start_; }
1460+
ptrdiff_t Value<_Alloc, _String>::getOffsetStart() const { return start_; }
14581461

14591462
template<class _Alloc, class _String>
1460-
size_t Value<_Alloc, _String>::getOffsetLimit() const { return limit_; }
1463+
ptrdiff_t Value<_Alloc, _String>::getOffsetLimit() const { return limit_; }
14611464

14621465
template<class _Alloc, class _String>
14631466
_String Value<_Alloc, _String>::toStyledString() const {

0 commit comments

Comments
 (0)