Skip to content

Commit 2968ced

Browse files
author
Christopher Dawes
committed
Merge pull request #2 from open-source-parsers/master
Merge jsoncpp latest changes to forked master
2 parents 0804322 + 9a4b1e3 commit 2968ced

File tree

12 files changed

+85
-62
lines changed

12 files changed

+85
-62
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ CTestTestFile.cmake
3434
cmake_install.cmake
3535
pkg-config/jsoncpp.pc
3636
jsoncpp_lib_static.dir/
37+
38+
# In case someone runs cmake in the root-dir:
39+
/CMakeCache.txt
40+
/Makefile
41+
/include/Makefile
42+
/src/Makefile
43+
/src/jsontestrunner/Makefile
44+
/src/jsontestrunner/jsontestrunner_exe
45+
/src/lib_json/Makefile
46+
/src/test_lib_json/Makefile
47+
/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)

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
@@ -42,8 +42,8 @@ class JSON_API Reader {
4242
*
4343
*/
4444
struct StructuredError {
45-
size_t offset_start;
46-
size_t offset_limit;
45+
ptrdiff_t offset_start;
46+
ptrdiff_t offset_limit;
4747
std::string message;
4848
};
4949

include/json/value.h

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

555555
// Accessors for the [start, limit) range of bytes within the JSON text from
556556
// which this value was parsed, if any.
557-
void setOffsetStart(size_t start);
558-
void setOffsetLimit(size_t limit);
559-
size_t getOffsetStart() const;
560-
size_t getOffsetLimit() const;
557+
void setOffsetStart(ptrdiff_t start);
558+
void setOffsetLimit(ptrdiff_t limit);
559+
ptrdiff_t getOffsetStart() const;
560+
ptrdiff_t getOffsetLimit() const;
561561

562562
private:
563563
void initBasic(ValueType type, bool allocated = false);
@@ -598,8 +598,8 @@ Json::Value obj_value(Json::objectValue); // {}
598598

599599
// [start, limit) byte offsets in the source JSON text from which this Value
600600
// was extracted.
601-
size_t start_;
602-
size_t limit_;
601+
ptrdiff_t start_;
602+
ptrdiff_t limit_;
603603
};
604604

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

include/json/version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#ifndef JSON_VERSION_H_INCLUDED
44
# define JSON_VERSION_H_INCLUDED
55

6-
# define JSONCPP_VERSION_STRING "1.6.5"
6+
# define JSONCPP_VERSION_STRING "1.7.0"
77
# define JSONCPP_VERSION_MAJOR 1
8-
# define JSONCPP_VERSION_MINOR 6
9-
# define JSONCPP_VERSION_PATCH 5
8+
# define JSONCPP_VERSION_MINOR 7
9+
# define JSONCPP_VERSION_PATCH 0
1010
# define JSONCPP_VERSION_QUALIFIER
1111
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
1212

include/json/writer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ class JSON_API StyledWriter : public Writer {
238238
ChildValues childValues_;
239239
std::string document_;
240240
std::string indentString_;
241-
int rightMargin_;
242-
int indentSize_;
241+
unsigned int rightMargin_;
242+
unsigned int indentSize_;
243243
bool addChildValues_;
244244
};
245245

@@ -302,7 +302,7 @@ class JSON_API StyledStreamWriter {
302302
ChildValues childValues_;
303303
std::ostream* document_;
304304
std::string indentString_;
305-
int rightMargin_;
305+
unsigned int rightMargin_;
306306
std::string indentation_;
307307
bool addChildValues_ : 1;
308308
bool indented_ : 1;

src/jsontestrunner/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ static std::string readInputTestFile(const char* path) {
5757
if (!file)
5858
return std::string("");
5959
fseek(file, 0, SEEK_END);
60-
long size = ftell(file);
60+
long const size = ftell(file);
61+
unsigned long const usize = static_cast<unsigned long const>(size);
6162
fseek(file, 0, SEEK_SET);
6263
std::string text;
6364
char* buffer = new char[size + 1];
6465
buffer[size] = 0;
65-
if (fread(buffer, 1, size, file) == (unsigned long)size)
66+
if (fread(buffer, 1, usize, file) == usize)
6667
text = buffer;
6768
fclose(file);
6869
delete[] buffer;
@@ -104,8 +105,8 @@ printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
104105
break;
105106
case Json::arrayValue: {
106107
fprintf(fout, "%s=[]\n", path.c_str());
107-
int size = value.size();
108-
for (int index = 0; index < size; ++index) {
108+
Json::ArrayIndex size = value.size();
109+
for (Json::ArrayIndex index = 0; index < size; ++index) {
109110
static char buffer[16];
110111
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
111112
sprintf_s(buffer, sizeof(buffer), "[%d]", index);

src/lib_json/json_reader.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
#elif defined(__ANDROID__) || defined(__QNXNTO__)
3131
#define snprintf snprintf
3232
#elif __cplusplus >= 201103L
33+
#if !defined(__MINGW32__)
3334
#define snprintf std::snprintf
3435
#endif
36+
#endif
3537

3638
#if defined(__QNXNTO__)
3739
#define sscanf std::sscanf
@@ -368,7 +370,7 @@ bool Reader::readComment() {
368370

369371
static std::string normalizeEOL(Reader::Location begin, Reader::Location end) {
370372
std::string normalized;
371-
normalized.reserve(end - begin);
373+
normalized.reserve(static_cast<size_t>(end - begin));
372374
Reader::Location current = begin;
373375
while (current != end) {
374376
char c = *current++;
@@ -578,7 +580,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
578580
Char c = *current++;
579581
if (c < '0' || c > '9')
580582
return decodeDouble(token, decoded);
581-
Value::UInt digit(c - '0');
583+
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
582584
if (value >= threshold) {
583585
// We've hit or exceeded the max value divided by 10 (rounded down). If
584586
// a) we've only just touched the limit, b) this is the last digit, and
@@ -636,7 +638,7 @@ bool Reader::decodeString(Token& token) {
636638
}
637639

638640
bool Reader::decodeString(Token& token, std::string& decoded) {
639-
decoded.reserve(token.end_ - token.start_ - 2);
641+
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
640642
Location current = token.start_ + 1; // skip '"'
641643
Location end = token.end_ - 1; // do not include '"'
642644
while (current != end) {
@@ -720,13 +722,13 @@ bool Reader::decodeUnicodeCodePoint(Token& token,
720722
bool Reader::decodeUnicodeEscapeSequence(Token& token,
721723
Location& current,
722724
Location end,
723-
unsigned int& unicode) {
725+
unsigned int& ret_unicode) {
724726
if (end - current < 4)
725727
return addError(
726728
"Bad unicode escape sequence in string: four digits expected.",
727729
token,
728730
current);
729-
unicode = 0;
731+
int unicode = 0;
730732
for (int index = 0; index < 4; ++index) {
731733
Char c = *current++;
732734
unicode *= 16;
@@ -742,6 +744,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
742744
token,
743745
current);
744746
}
747+
ret_unicode = static_cast<unsigned int>(unicode);
745748
return true;
746749
}
747750

@@ -756,7 +759,7 @@ Reader::addError(const std::string& message, Token& token, Location extra) {
756759
}
757760

758761
bool Reader::recoverFromError(TokenType skipUntilToken) {
759-
int errorCount = int(errors_.size());
762+
size_t const errorCount = errors_.size();
760763
Token skip;
761764
for (;;) {
762765
if (!readToken(skip))
@@ -851,7 +854,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
851854
}
852855

853856
bool Reader::pushError(const Value& value, const std::string& message) {
854-
size_t length = end_ - begin_;
857+
ptrdiff_t const length = end_ - begin_;
855858
if(value.getOffsetStart() > length
856859
|| value.getOffsetLimit() > length)
857860
return false;
@@ -868,7 +871,7 @@ bool Reader::pushError(const Value& value, const std::string& message) {
868871
}
869872

870873
bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) {
871-
size_t length = end_ - begin_;
874+
ptrdiff_t const length = end_ - begin_;
872875
if(value.getOffsetStart() > length
873876
|| value.getOffsetLimit() > length
874877
|| extra.getOffsetLimit() > length)
@@ -918,8 +921,8 @@ class OurReader {
918921
typedef char Char;
919922
typedef const Char* Location;
920923
struct StructuredError {
921-
size_t offset_start;
922-
size_t offset_limit;
924+
ptrdiff_t offset_start;
925+
ptrdiff_t offset_limit;
923926
std::string message;
924927
};
925928

@@ -1560,7 +1563,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
15601563
Char c = *current++;
15611564
if (c < '0' || c > '9')
15621565
return decodeDouble(token, decoded);
1563-
Value::UInt digit(c - '0');
1566+
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
15641567
if (value >= threshold) {
15651568
// We've hit or exceeded the max value divided by 10 (rounded down). If
15661569
// a) we've only just touched the limit, b) this is the last digit, and
@@ -1596,12 +1599,13 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
15961599
double value = 0;
15971600
const int bufferSize = 32;
15981601
int count;
1599-
int length = int(token.end_ - token.start_);
1602+
ptrdiff_t const length = token.end_ - token.start_;
16001603

16011604
// Sanity check to avoid buffer overflow exploits.
16021605
if (length < 0) {
16031606
return addError("Unable to parse token length", token);
16041607
}
1608+
size_t const ulength = static_cast<size_t>(length);
16051609

16061610
// Avoid using a string constant for the format control string given to
16071611
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
@@ -1612,7 +1616,7 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
16121616

16131617
if (length <= bufferSize) {
16141618
Char buffer[bufferSize + 1];
1615-
memcpy(buffer, token.start_, length);
1619+
memcpy(buffer, token.start_, ulength);
16161620
buffer[length] = 0;
16171621
count = sscanf(buffer, format, &value);
16181622
} else {
@@ -1640,7 +1644,7 @@ bool OurReader::decodeString(Token& token) {
16401644
}
16411645

16421646
bool OurReader::decodeString(Token& token, std::string& decoded) {
1643-
decoded.reserve(token.end_ - token.start_ - 2);
1647+
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
16441648
Location current = token.start_ + 1; // skip '"'
16451649
Location end = token.end_ - 1; // do not include '"'
16461650
while (current != end) {
@@ -1724,13 +1728,13 @@ bool OurReader::decodeUnicodeCodePoint(Token& token,
17241728
bool OurReader::decodeUnicodeEscapeSequence(Token& token,
17251729
Location& current,
17261730
Location end,
1727-
unsigned int& unicode) {
1731+
unsigned int& ret_unicode) {
17281732
if (end - current < 4)
17291733
return addError(
17301734
"Bad unicode escape sequence in string: four digits expected.",
17311735
token,
17321736
current);
1733-
unicode = 0;
1737+
int unicode = 0;
17341738
for (int index = 0; index < 4; ++index) {
17351739
Char c = *current++;
17361740
unicode *= 16;
@@ -1746,6 +1750,7 @@ bool OurReader::decodeUnicodeEscapeSequence(Token& token,
17461750
token,
17471751
current);
17481752
}
1753+
ret_unicode = static_cast<unsigned int>(unicode);
17491754
return true;
17501755
}
17511756

@@ -1760,7 +1765,7 @@ OurReader::addError(const std::string& message, Token& token, Location extra) {
17601765
}
17611766

17621767
bool OurReader::recoverFromError(TokenType skipUntilToken) {
1763-
int errorCount = int(errors_.size());
1768+
size_t errorCount = errors_.size();
17641769
Token skip;
17651770
for (;;) {
17661771
if (!readToken(skip))
@@ -1850,7 +1855,7 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
18501855
}
18511856

18521857
bool OurReader::pushError(const Value& value, const std::string& message) {
1853-
size_t length = end_ - begin_;
1858+
ptrdiff_t length = end_ - begin_;
18541859
if(value.getOffsetStart() > length
18551860
|| value.getOffsetLimit() > length)
18561861
return false;
@@ -1867,7 +1872,7 @@ bool OurReader::pushError(const Value& value, const std::string& message) {
18671872
}
18681873

18691874
bool OurReader::pushError(const Value& value, const std::string& message, const Value& extra) {
1870-
size_t length = end_ - begin_;
1875+
ptrdiff_t length = end_ - begin_;
18711876
if(value.getOffsetStart() > length
18721877
|| value.getOffsetLimit() > length
18731878
|| extra.getOffsetLimit() > length)

src/lib_json/json_value.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
5555
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
5656
template <typename T, typename U>
5757
static inline bool InRange(double d, T min, U max) {
58+
// The casts can lose precision, but we are looking only for
59+
// an approximate range. Might fail on edge cases though. ~cdunn
60+
//return d >= static_cast<double>(min) && d <= static_cast<double>(max);
5861
return d >= min && d <= max;
5962
}
6063
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
@@ -1332,13 +1335,13 @@ std::string Value::getComment(CommentPlacement placement) const {
13321335
return "";
13331336
}
13341337

1335-
void Value::setOffsetStart(size_t start) { start_ = start; }
1338+
void Value::setOffsetStart(ptrdiff_t start) { start_ = start; }
13361339

1337-
void Value::setOffsetLimit(size_t limit) { limit_ = limit; }
1340+
void Value::setOffsetLimit(ptrdiff_t limit) { limit_ = limit; }
13381341

1339-
size_t Value::getOffsetStart() const { return start_; }
1342+
ptrdiff_t Value::getOffsetStart() const { return start_; }
13401343

1341-
size_t Value::getOffsetLimit() const { return limit_; }
1344+
ptrdiff_t Value::getOffsetLimit() const { return limit_; }
13421345

13431346
std::string Value::toStyledString() const {
13441347
StyledWriter writer;

0 commit comments

Comments
 (0)