Skip to content

Commit

Permalink
Merge pull request #315 from cdunn2001/0.y.z
Browse files Browse the repository at this point in the history
-Werror

and fixed a minor bug found by -Wshadow
  • Loading branch information
cdunn2001 committed Jul 12, 2015
2 parents 02839ef + ed5d73f commit 93d7467
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ENDMACRO(jsoncpp_parse_version)
#SET( JSONCPP_VERSION_MAJOR X )
#SET( JSONCPP_VERSION_MINOR Y )
#SET( JSONCPP_VERSION_PATCH Z )
SET( JSONCPP_VERSION 0.10.3 )
SET( JSONCPP_VERSION 0.10.4 )
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
#IF(NOT JSONCPP_VERSION_FOUND)
# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
Expand Down Expand Up @@ -97,10 +97,11 @@ endif( MSVC )

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# 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 -Wshadow -Wshorten-64-to-32")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wshadow -Wextra -pedantic -Wno-long-long")
# not yet ready for -Wconversion
endif()

IF(JSONCPP_WITH_WARNING_AS_ERROR)
Expand Down
4 changes: 2 additions & 2 deletions include/json/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#ifndef JSON_VERSION_H_INCLUDED
# define JSON_VERSION_H_INCLUDED

# define JSONCPP_VERSION_STRING "0.10.3"
# define JSONCPP_VERSION_STRING "0.10.4"
# define JSONCPP_VERSION_MAJOR 0
# define JSONCPP_VERSION_MINOR 10
# define JSONCPP_VERSION_PATCH 3
# define JSONCPP_VERSION_PATCH 4
# define JSONCPP_VERSION_QUALIFIER
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))

Expand Down
6 changes: 3 additions & 3 deletions src/lib_json/json_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ static inline std::string codePointToUTF8(unsigned int cp) {
} else if (cp <= 0xFFFF) {
result.resize(3);
result[2] = static_cast<char>(0x80 | (0x3f & cp));
result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
} else if (cp <= 0x10FFFF) {
result.resize(4);
result[3] = static_cast<char>(0x80 | (0x3f & cp));
Expand Down Expand Up @@ -63,7 +63,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
static inline void uintToString(LargestUInt value, char*& current) {
*--current = 0;
do {
*--current = char(value % 10) + '0';
*--current = static_cast<signed char>(value % 10U + static_cast<unsigned>('0'));
value /= 10;
} while (value != 0);
}
Expand Down
57 changes: 29 additions & 28 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static inline char* duplicateAndPrefixStringValue(
JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U,
"in Json::Value::duplicateAndPrefixStringValue(): "
"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));
if (newString == 0) {
throwRuntimeError(
Expand Down Expand Up @@ -233,14 +233,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
// Notes: policy_ indicates if the string was allocated when
// 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)
{
// allocate != duplicate
storage_.policy_ = allocate;
storage_.length_ = length;
storage_.policy_ = allocate & 0x3;
storage_.length_ = ulength & 0x3FFFFFFF;
}

Value::CZString::CZString(const CZString& other)
Expand All @@ -249,9 +249,9 @@ Value::CZString::CZString(const CZString& other)
: other.cstr_)
{
storage_.policy_ = (other.cstr_
? (other.storage_.policy_ == noDuplication
? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
? noDuplication : duplicate)
: other.storage_.policy_);
: static_cast<DuplicationPolicy>(other.storage_.policy_));
storage_.length_ = other.storage_.length_;
}

Expand Down Expand Up @@ -313,9 +313,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
* memset( this, 0, sizeof(Value) )
* This optimization is used in ValueInternalMap fast allocator.
*/
Value::Value(ValueType type) {
initBasic(type);
switch (type) {
Value::Value(ValueType vtype) {
initBasic(vtype);
switch (vtype) {
case nullValue:
break;
case intValue:
Expand Down Expand Up @@ -480,7 +480,7 @@ void Value::swapPayload(Value& other) {
std::swap(value_, other.value_);
int temp2 = allocated_;
allocated_ = other.allocated_;
other.allocated_ = temp2;
other.allocated_ = temp2 & 0x1;
}

void Value::swap(Value& other) {
Expand Down Expand Up @@ -606,12 +606,12 @@ const char* Value::asCString() const {
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 (value_.string_ == 0) return false;
unsigned length;
decodePrefixedString(this->allocated_, this->value_.string_, &length, str);
*end = *str + length;
*cend = *str + length;
return true;
}

Expand Down Expand Up @@ -810,7 +810,8 @@ bool Value::asBool() const {
case uintValue:
return value_.uint_ ? true : false;
case realValue:
return value_.real_ ? true : false;
// This is kind of strange. Not recommended.
return (value_.real_ != 0.0) ? true : false;
default:
break;
}
Expand Down Expand Up @@ -958,8 +959,8 @@ const Value& Value::operator[](int index) const {
return (*this)[ArrayIndex(index)];
}

void Value::initBasic(ValueType type, bool allocated) {
type_ = type;
void Value::initBasic(ValueType vtype, bool allocated) {
type_ = vtype;
allocated_ = allocated;
comments_ = 0;
}
Expand All @@ -986,15 +987,15 @@ Value& Value::resolveReference(const char* key) {
}

// @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(
type_ == nullValue || type_ == objectValue,
"in Json::Value::resolveReference(key, end): requires objectValue");
if (type_ == nullValue)
*this = Value(objectValue);
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);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
Expand All @@ -1012,13 +1013,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const {

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(
type_ == nullValue || type_ == objectValue,
"in Json::Value::find(key, end, found): requires objectValue or nullValue");
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);
if (it == value_.map_->end()) return NULL;
return &(*it).second;
Expand Down Expand Up @@ -1062,9 +1063,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const

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;
}
Value Value::get(char const* key, Value const& defaultValue) const
Expand All @@ -1077,12 +1078,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) {
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);
if (it == value_.map_->end())
return false;
Expand Down Expand Up @@ -1127,8 +1128,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
ArrayIndex oldSize = size();
// shift left all items left, into the place of the "removed"
for (ArrayIndex i = index; i < (oldSize - 1); ++i){
CZString key(i);
(*value_.map_)[key] = (*this)[i + 1];
CZString keey(i);
(*value_.map_)[keey] = (*this)[i + 1];
}
// erase the last one ("leftover")
CZString keyLast(oldSize - 1);
Expand All @@ -1144,9 +1145,9 @@ Value Value::get(const CppTL::ConstString& key,
}
#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;
}
bool Value::isMember(char const* key) const
Expand Down
20 changes: 10 additions & 10 deletions src/lib_json/json_valueiterator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,26 @@ UInt ValueIteratorBase::index() const {
}

std::string ValueIteratorBase::name() const {
char const* key;
char const* keey;
char const* end;
key = memberName(&end);
if (!key) return std::string();
return std::string(key, end);
keey = memberName(&end);
if (!keey) return std::string();
return std::string(keey, end);
}

char const* ValueIteratorBase::memberName() const {
const char* name = (*current_).first.data();
return name ? name : "";
const char* cname = (*current_).first.data();
return cname ? cname : "";
}

char const* ValueIteratorBase::memberName(char const** end) const {
const char* name = (*current_).first.data();
if (!name) {
const char* cname = (*current_).first.data();
if (!cname) {
*end = NULL;
return NULL;
}
*end = name + (*current_).first.length();
return name;
*end = cname + (*current_).first.length();
return cname;
}

// //////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.3
0.10.4

0 comments on commit 93d7467

Please sign in to comment.