Merge pull request #314 from cdunn2001/master

-Werror

plus small bug-fix
This commit is contained in:
Christopher Dunn 2015-07-12 14:38:02 -05:00
commit 81cf237917
6 changed files with 49 additions and 47 deletions

View File

@ -63,7 +63,7 @@ ENDMACRO(jsoncpp_parse_version)
#SET( JSONCPP_VERSION_MAJOR X ) #SET( JSONCPP_VERSION_MAJOR X )
#SET( JSONCPP_VERSION_MINOR Y ) #SET( JSONCPP_VERSION_MINOR Y )
#SET( JSONCPP_VERSION_PATCH Z ) #SET( JSONCPP_VERSION_PATCH Z )
SET( JSONCPP_VERSION 1.6.3 ) SET( JSONCPP_VERSION 1.6.4 )
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
#IF(NOT JSONCPP_VERSION_FOUND) #IF(NOT JSONCPP_VERSION_FOUND)
# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z") # MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
@ -97,10 +97,11 @@ endif( MSVC )
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang # using regular Clang or AppleClang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshorten-64-to-32") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wconversion -Wshadow -Wno-sign-conversion")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC # using GCC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wconversion -Wshadow -Wextra -pedantic")
# not yet ready for -Wsign-conversion
endif() endif()
IF(JSONCPP_WITH_WARNING_AS_ERROR) IF(JSONCPP_WITH_WARNING_AS_ERROR)

View File

@ -3,10 +3,10 @@
#ifndef JSON_VERSION_H_INCLUDED #ifndef JSON_VERSION_H_INCLUDED
# define JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED
# define JSONCPP_VERSION_STRING "1.6.3" # define JSONCPP_VERSION_STRING "1.6.4"
# define JSONCPP_VERSION_MAJOR 1 # define JSONCPP_VERSION_MAJOR 1
# define JSONCPP_VERSION_MINOR 6 # define JSONCPP_VERSION_MINOR 6
# define JSONCPP_VERSION_PATCH 3 # define JSONCPP_VERSION_PATCH 4
# define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_QUALIFIER
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))

View File

@ -30,8 +30,8 @@ static inline std::string codePointToUTF8(unsigned int cp) {
} else if (cp <= 0xFFFF) { } else if (cp <= 0xFFFF) {
result.resize(3); result.resize(3);
result[2] = static_cast<char>(0x80 | (0x3f & cp)); result[2] = static_cast<char>(0x80 | (0x3f & cp));
result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6))); result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12))); result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
} else if (cp <= 0x10FFFF) { } else if (cp <= 0x10FFFF) {
result.resize(4); result.resize(4);
result[3] = static_cast<char>(0x80 | (0x3f & cp)); result[3] = static_cast<char>(0x80 | (0x3f & cp));
@ -63,7 +63,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
static inline void uintToString(LargestUInt value, char*& current) { static inline void uintToString(LargestUInt value, char*& current) {
*--current = 0; *--current = 0;
do { do {
*--current = char(value % 10) + '0'; *--current = static_cast<signed char>(value % 10U + static_cast<unsigned>('0'));
value /= 10; value /= 10;
} while (value != 0); } while (value != 0);
} }

View File

@ -108,7 +108,7 @@ static inline char* duplicateAndPrefixStringValue(
JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U, JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U,
"in Json::Value::duplicateAndPrefixStringValue(): " "in Json::Value::duplicateAndPrefixStringValue(): "
"length too big for prefixing"); "length too big for prefixing");
unsigned actualLength = length + sizeof(unsigned) + 1U; unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
char* newString = static_cast<char*>(malloc(actualLength)); char* newString = static_cast<char*>(malloc(actualLength));
if (newString == 0) { if (newString == 0) {
throwRuntimeError( throwRuntimeError(
@ -232,14 +232,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
// Notes: policy_ indicates if the string was allocated when // Notes: policy_ indicates if the string was allocated when
// a string is stored. // a string is stored.
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {} Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {}
Value::CZString::CZString(char const* str, unsigned length, DuplicationPolicy allocate) Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate)
: cstr_(str) : cstr_(str)
{ {
// allocate != duplicate // allocate != duplicate
storage_.policy_ = allocate; storage_.policy_ = allocate & 0x3;
storage_.length_ = length; storage_.length_ = ulength & 0x3FFFFFFF;
} }
Value::CZString::CZString(const CZString& other) Value::CZString::CZString(const CZString& other)
@ -248,9 +248,9 @@ Value::CZString::CZString(const CZString& other)
: other.cstr_) : other.cstr_)
{ {
storage_.policy_ = (other.cstr_ storage_.policy_ = (other.cstr_
? (other.storage_.policy_ == noDuplication ? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
? noDuplication : duplicate) ? noDuplication : duplicate)
: other.storage_.policy_); : static_cast<DuplicationPolicy>(other.storage_.policy_));
storage_.length_ = other.storage_.length_; storage_.length_ = other.storage_.length_;
} }
@ -312,9 +312,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
* memset( this, 0, sizeof(Value) ) * memset( this, 0, sizeof(Value) )
* This optimization is used in ValueInternalMap fast allocator. * This optimization is used in ValueInternalMap fast allocator.
*/ */
Value::Value(ValueType type) { Value::Value(ValueType vtype) {
initBasic(type); initBasic(vtype);
switch (type) { switch (vtype) {
case nullValue: case nullValue:
break; break;
case intValue: case intValue:
@ -478,7 +478,7 @@ void Value::swapPayload(Value& other) {
std::swap(value_, other.value_); std::swap(value_, other.value_);
int temp2 = allocated_; int temp2 = allocated_;
allocated_ = other.allocated_; allocated_ = other.allocated_;
other.allocated_ = temp2; other.allocated_ = temp2 & 0x1;
} }
void Value::swap(Value& other) { void Value::swap(Value& other) {
@ -606,12 +606,12 @@ const char* Value::asCString() const {
return this_str; return this_str;
} }
bool Value::getString(char const** str, char const** end) const { bool Value::getString(char const** str, char const** cend) const {
if (type_ != stringValue) return false; if (type_ != stringValue) return false;
if (value_.string_ == 0) return false; if (value_.string_ == 0) return false;
unsigned length; unsigned length;
decodePrefixedString(this->allocated_, this->value_.string_, &length, str); decodePrefixedString(this->allocated_, this->value_.string_, &length, str);
*end = *str + length; *cend = *str + length;
return true; return true;
} }
@ -810,7 +810,8 @@ bool Value::asBool() const {
case uintValue: case uintValue:
return value_.uint_ ? true : false; return value_.uint_ ? true : false;
case realValue: case realValue:
return value_.real_ ? true : false; // This is kind of strange. Not recommended.
return (value_.real_ != 0.0) ? true : false;
default: default:
break; break;
} }
@ -960,8 +961,8 @@ const Value& Value::operator[](int index) const {
return (*this)[ArrayIndex(index)]; return (*this)[ArrayIndex(index)];
} }
void Value::initBasic(ValueType type, bool allocated) { void Value::initBasic(ValueType vtype, bool allocated) {
type_ = type; type_ = vtype;
allocated_ = allocated; allocated_ = allocated;
comments_ = 0; comments_ = 0;
start_ = 0; start_ = 0;
@ -990,7 +991,7 @@ Value& Value::resolveReference(const char* key) {
} }
// @param key is not null-terminated. // @param key is not null-terminated.
Value& Value::resolveReference(char const* key, char const* end) Value& Value::resolveReference(char const* key, char const* cend)
{ {
JSON_ASSERT_MESSAGE( JSON_ASSERT_MESSAGE(
type_ == nullValue || type_ == objectValue, type_ == nullValue || type_ == objectValue,
@ -998,7 +999,7 @@ Value& Value::resolveReference(char const* key, char const* end)
if (type_ == nullValue) if (type_ == nullValue)
*this = Value(objectValue); *this = Value(objectValue);
CZString actualKey( CZString actualKey(
key, static_cast<unsigned>(end-key), CZString::duplicateOnCopy); key, static_cast<unsigned>(cend-key), CZString::duplicateOnCopy);
ObjectValues::iterator it = value_.map_->lower_bound(actualKey); ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey) if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second; return (*it).second;
@ -1016,13 +1017,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const {
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); } bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
Value const* Value::find(char const* key, char const* end) const Value const* Value::find(char const* key, char const* cend) const
{ {
JSON_ASSERT_MESSAGE( JSON_ASSERT_MESSAGE(
type_ == nullValue || type_ == objectValue, type_ == nullValue || type_ == objectValue,
"in Json::Value::find(key, end, found): requires objectValue or nullValue"); "in Json::Value::find(key, end, found): requires objectValue or nullValue");
if (type_ == nullValue) return NULL; if (type_ == nullValue) return NULL;
CZString actualKey(key, static_cast<unsigned>(end-key), CZString::noDuplication); CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
ObjectValues::const_iterator it = value_.map_->find(actualKey); ObjectValues::const_iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end()) return NULL; if (it == value_.map_->end()) return NULL;
return &(*it).second; return &(*it).second;
@ -1066,9 +1067,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const
Value& Value::append(const Value& value) { return (*this)[size()] = value; } Value& Value::append(const Value& value) { return (*this)[size()] = value; }
Value Value::get(char const* key, char const* end, Value const& defaultValue) const Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
{ {
Value const* found = find(key, end); Value const* found = find(key, cend);
return !found ? defaultValue : *found; return !found ? defaultValue : *found;
} }
Value Value::get(char const* key, Value const& defaultValue) const 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
} }
bool Value::removeMember(const char* key, const char* end, Value* removed) bool Value::removeMember(const char* key, const char* cend, Value* removed)
{ {
if (type_ != objectValue) { if (type_ != objectValue) {
return false; return false;
} }
CZString actualKey(key, static_cast<unsigned>(end-key), CZString::noDuplication); CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
ObjectValues::iterator it = value_.map_->find(actualKey); ObjectValues::iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end()) if (it == value_.map_->end())
return false; return false;
@ -1131,8 +1132,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
ArrayIndex oldSize = size(); ArrayIndex oldSize = size();
// shift left all items left, into the place of the "removed" // shift left all items left, into the place of the "removed"
for (ArrayIndex i = index; i < (oldSize - 1); ++i){ for (ArrayIndex i = index; i < (oldSize - 1); ++i){
CZString key(i); CZString keey(i);
(*value_.map_)[key] = (*this)[i + 1]; (*value_.map_)[keey] = (*this)[i + 1];
} }
// erase the last one ("leftover") // erase the last one ("leftover")
CZString keyLast(oldSize - 1); CZString keyLast(oldSize - 1);
@ -1148,9 +1149,9 @@ Value Value::get(const CppTL::ConstString& key,
} }
#endif #endif
bool Value::isMember(char const* key, char const* end) const bool Value::isMember(char const* key, char const* cend) const
{ {
Value const* value = find(key, end); Value const* value = find(key, cend);
return NULL != value; return NULL != value;
} }
bool Value::isMember(char const* key) const bool Value::isMember(char const* key) const

View File

@ -93,26 +93,26 @@ UInt ValueIteratorBase::index() const {
} }
std::string ValueIteratorBase::name() const { std::string ValueIteratorBase::name() const {
char const* key; char const* keey;
char const* end; char const* end;
key = memberName(&end); keey = memberName(&end);
if (!key) return std::string(); if (!keey) return std::string();
return std::string(key, end); return std::string(keey, end);
} }
char const* ValueIteratorBase::memberName() const { char const* ValueIteratorBase::memberName() const {
const char* name = (*current_).first.data(); const char* cname = (*current_).first.data();
return name ? name : ""; return cname ? cname : "";
} }
char const* ValueIteratorBase::memberName(char const** end) const { char const* ValueIteratorBase::memberName(char const** end) const {
const char* name = (*current_).first.data(); const char* cname = (*current_).first.data();
if (!name) { if (!cname) {
*end = NULL; *end = NULL;
return NULL; return NULL;
} }
*end = name + (*current_).first.length(); *end = cname + (*current_).first.length();
return name; return cname;
} }
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////

View File

@ -1 +1 @@
1.6.3 1.6.4