Skip to content

Commit 81cf237

Browse files
committed
Merge pull request open-source-parsers#314 from cdunn2001/master
-Werror plus small bug-fix
2 parents f94a0e8 + cac7954 commit 81cf237

File tree

6 files changed

+49
-47
lines changed

6 files changed

+49
-47
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ENDMACRO(jsoncpp_parse_version)
6363
#SET( JSONCPP_VERSION_MAJOR X )
6464
#SET( JSONCPP_VERSION_MINOR Y )
6565
#SET( JSONCPP_VERSION_PATCH Z )
66-
SET( JSONCPP_VERSION 1.6.3 )
66+
SET( JSONCPP_VERSION 1.6.4 )
6767
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
6868
#IF(NOT JSONCPP_VERSION_FOUND)
6969
# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
@@ -97,10 +97,11 @@ endif( MSVC )
9797

9898
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9999
# using regular Clang or AppleClang
100-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshorten-64-to-32")
100+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wconversion -Wshadow -Wno-sign-conversion")
101101
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
102102
# using GCC
103-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic")
103+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wconversion -Wshadow -Wextra -pedantic")
104+
# not yet ready for -Wsign-conversion
104105
endif()
105106

106107
IF(JSONCPP_WITH_WARNING_AS_ERROR)

include/json/version.h

Lines changed: 2 additions & 2 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.3"
6+
# define JSONCPP_VERSION_STRING "1.6.4"
77
# define JSONCPP_VERSION_MAJOR 1
88
# define JSONCPP_VERSION_MINOR 6
9-
# define JSONCPP_VERSION_PATCH 3
9+
# define JSONCPP_VERSION_PATCH 4
1010
# define JSONCPP_VERSION_QUALIFIER
1111
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
1212

src/lib_json/json_tool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ static inline std::string codePointToUTF8(unsigned int cp) {
3030
} else if (cp <= 0xFFFF) {
3131
result.resize(3);
3232
result[2] = static_cast<char>(0x80 | (0x3f & cp));
33-
result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
34-
result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
33+
result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
34+
result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
3535
} else if (cp <= 0x10FFFF) {
3636
result.resize(4);
3737
result[3] = static_cast<char>(0x80 | (0x3f & cp));
@@ -63,7 +63,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
6363
static inline void uintToString(LargestUInt value, char*& current) {
6464
*--current = 0;
6565
do {
66-
*--current = char(value % 10) + '0';
66+
*--current = static_cast<signed char>(value % 10U + static_cast<unsigned>('0'));
6767
value /= 10;
6868
} while (value != 0);
6969
}

src/lib_json/json_value.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline char* duplicateAndPrefixStringValue(
108108
JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U,
109109
"in Json::Value::duplicateAndPrefixStringValue(): "
110110
"length too big for prefixing");
111-
unsigned actualLength = length + sizeof(unsigned) + 1U;
111+
unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
112112
char* newString = static_cast<char*>(malloc(actualLength));
113113
if (newString == 0) {
114114
throwRuntimeError(
@@ -232,14 +232,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
232232
// Notes: policy_ indicates if the string was allocated when
233233
// a string is stored.
234234

235-
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
235+
Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {}
236236

237-
Value::CZString::CZString(char const* str, unsigned length, DuplicationPolicy allocate)
237+
Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate)
238238
: cstr_(str)
239239
{
240240
// allocate != duplicate
241-
storage_.policy_ = allocate;
242-
storage_.length_ = length;
241+
storage_.policy_ = allocate & 0x3;
242+
storage_.length_ = ulength & 0x3FFFFFFF;
243243
}
244244

245245
Value::CZString::CZString(const CZString& other)
@@ -248,9 +248,9 @@ Value::CZString::CZString(const CZString& other)
248248
: other.cstr_)
249249
{
250250
storage_.policy_ = (other.cstr_
251-
? (other.storage_.policy_ == noDuplication
251+
? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
252252
? noDuplication : duplicate)
253-
: other.storage_.policy_);
253+
: static_cast<DuplicationPolicy>(other.storage_.policy_));
254254
storage_.length_ = other.storage_.length_;
255255
}
256256

@@ -312,9 +312,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
312312
* memset( this, 0, sizeof(Value) )
313313
* This optimization is used in ValueInternalMap fast allocator.
314314
*/
315-
Value::Value(ValueType type) {
316-
initBasic(type);
317-
switch (type) {
315+
Value::Value(ValueType vtype) {
316+
initBasic(vtype);
317+
switch (vtype) {
318318
case nullValue:
319319
break;
320320
case intValue:
@@ -478,7 +478,7 @@ void Value::swapPayload(Value& other) {
478478
std::swap(value_, other.value_);
479479
int temp2 = allocated_;
480480
allocated_ = other.allocated_;
481-
other.allocated_ = temp2;
481+
other.allocated_ = temp2 & 0x1;
482482
}
483483

484484
void Value::swap(Value& other) {
@@ -606,12 +606,12 @@ const char* Value::asCString() const {
606606
return this_str;
607607
}
608608

609-
bool Value::getString(char const** str, char const** end) const {
609+
bool Value::getString(char const** str, char const** cend) const {
610610
if (type_ != stringValue) return false;
611611
if (value_.string_ == 0) return false;
612612
unsigned length;
613613
decodePrefixedString(this->allocated_, this->value_.string_, &length, str);
614-
*end = *str + length;
614+
*cend = *str + length;
615615
return true;
616616
}
617617

@@ -810,7 +810,8 @@ bool Value::asBool() const {
810810
case uintValue:
811811
return value_.uint_ ? true : false;
812812
case realValue:
813-
return value_.real_ ? true : false;
813+
// This is kind of strange. Not recommended.
814+
return (value_.real_ != 0.0) ? true : false;
814815
default:
815816
break;
816817
}
@@ -960,8 +961,8 @@ const Value& Value::operator[](int index) const {
960961
return (*this)[ArrayIndex(index)];
961962
}
962963

963-
void Value::initBasic(ValueType type, bool allocated) {
964-
type_ = type;
964+
void Value::initBasic(ValueType vtype, bool allocated) {
965+
type_ = vtype;
965966
allocated_ = allocated;
966967
comments_ = 0;
967968
start_ = 0;
@@ -990,15 +991,15 @@ Value& Value::resolveReference(const char* key) {
990991
}
991992

992993
// @param key is not null-terminated.
993-
Value& Value::resolveReference(char const* key, char const* end)
994+
Value& Value::resolveReference(char const* key, char const* cend)
994995
{
995996
JSON_ASSERT_MESSAGE(
996997
type_ == nullValue || type_ == objectValue,
997998
"in Json::Value::resolveReference(key, end): requires objectValue");
998999
if (type_ == nullValue)
9991000
*this = Value(objectValue);
10001001
CZString actualKey(
1001-
key, static_cast<unsigned>(end-key), CZString::duplicateOnCopy);
1002+
key, static_cast<unsigned>(cend-key), CZString::duplicateOnCopy);
10021003
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
10031004
if (it != value_.map_->end() && (*it).first == actualKey)
10041005
return (*it).second;
@@ -1016,13 +1017,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const {
10161017

10171018
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
10181019

1019-
Value const* Value::find(char const* key, char const* end) const
1020+
Value const* Value::find(char const* key, char const* cend) const
10201021
{
10211022
JSON_ASSERT_MESSAGE(
10221023
type_ == nullValue || type_ == objectValue,
10231024
"in Json::Value::find(key, end, found): requires objectValue or nullValue");
10241025
if (type_ == nullValue) return NULL;
1025-
CZString actualKey(key, static_cast<unsigned>(end-key), CZString::noDuplication);
1026+
CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
10261027
ObjectValues::const_iterator it = value_.map_->find(actualKey);
10271028
if (it == value_.map_->end()) return NULL;
10281029
return &(*it).second;
@@ -1066,9 +1067,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const
10661067

10671068
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
10681069

1069-
Value Value::get(char const* key, char const* end, Value const& defaultValue) const
1070+
Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
10701071
{
1071-
Value const* found = find(key, end);
1072+
Value const* found = find(key, cend);
10721073
return !found ? defaultValue : *found;
10731074
}
10741075
Value Value::get(char const* key, Value const& defaultValue) const
@@ -1081,12 +1082,12 @@ Value Value::get(std::string const& key, Value const& defaultValue) const
10811082
}
10821083

10831084

1084-
bool Value::removeMember(const char* key, const char* end, Value* removed)
1085+
bool Value::removeMember(const char* key, const char* cend, Value* removed)
10851086
{
10861087
if (type_ != objectValue) {
10871088
return false;
10881089
}
1089-
CZString actualKey(key, static_cast<unsigned>(end-key), CZString::noDuplication);
1090+
CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
10901091
ObjectValues::iterator it = value_.map_->find(actualKey);
10911092
if (it == value_.map_->end())
10921093
return false;
@@ -1131,8 +1132,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
11311132
ArrayIndex oldSize = size();
11321133
// shift left all items left, into the place of the "removed"
11331134
for (ArrayIndex i = index; i < (oldSize - 1); ++i){
1134-
CZString key(i);
1135-
(*value_.map_)[key] = (*this)[i + 1];
1135+
CZString keey(i);
1136+
(*value_.map_)[keey] = (*this)[i + 1];
11361137
}
11371138
// erase the last one ("leftover")
11381139
CZString keyLast(oldSize - 1);
@@ -1148,9 +1149,9 @@ Value Value::get(const CppTL::ConstString& key,
11481149
}
11491150
#endif
11501151

1151-
bool Value::isMember(char const* key, char const* end) const
1152+
bool Value::isMember(char const* key, char const* cend) const
11521153
{
1153-
Value const* value = find(key, end);
1154+
Value const* value = find(key, cend);
11541155
return NULL != value;
11551156
}
11561157
bool Value::isMember(char const* key) const

src/lib_json/json_valueiterator.inl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,26 @@ UInt ValueIteratorBase::index() const {
9393
}
9494

9595
std::string ValueIteratorBase::name() const {
96-
char const* key;
96+
char const* keey;
9797
char const* end;
98-
key = memberName(&end);
99-
if (!key) return std::string();
100-
return std::string(key, end);
98+
keey = memberName(&end);
99+
if (!keey) return std::string();
100+
return std::string(keey, end);
101101
}
102102

103103
char const* ValueIteratorBase::memberName() const {
104-
const char* name = (*current_).first.data();
105-
return name ? name : "";
104+
const char* cname = (*current_).first.data();
105+
return cname ? cname : "";
106106
}
107107

108108
char const* ValueIteratorBase::memberName(char const** end) const {
109-
const char* name = (*current_).first.data();
110-
if (!name) {
109+
const char* cname = (*current_).first.data();
110+
if (!cname) {
111111
*end = NULL;
112112
return NULL;
113113
}
114-
*end = name + (*current_).first.length();
115-
return name;
114+
*end = cname + (*current_).first.length();
115+
return cname;
116116
}
117117

118118
// //////////////////////////////////////////////////////////////////

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.3
1+
1.6.4

0 commit comments

Comments
 (0)