From 17360f3d4bbfe9c5b47cf5aef11554d3a02c854a Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:55:18 -0500 Subject: [PATCH] fix some warnings --- src/lib_json/json_tool.h | 6 ++-- src/lib_json/json_value.cpp | 53 +++++++++++++++-------------- src/lib_json/json_valueiterator.inl | 20 +++++------ 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index f9b61c3..e6d4e92 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -30,8 +30,8 @@ static inline std::string codePointToUTF8(unsigned int cp) { } else if (cp <= 0xFFFF) { result.resize(3); result[2] = static_cast(0x80 | (0x3f & cp)); - result[1] = 0x80 | static_cast((0x3f & (cp >> 6))); - result[0] = 0xE0 | static_cast((0xf & (cp >> 12))); + result[1] = static_cast(0x80 | (0x3f & (cp >> 6))); + result[0] = static_cast(0xE0 | (0xf & (cp >> 12))); } else if (cp <= 0x10FFFF) { result.resize(4); result[3] = static_cast(0x80 | (0x3f & cp)); @@ -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(value % 10U + static_cast('0')); value /= 10; } while (value != 0); } diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 8e9af94..e3d45ec 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -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(sizeof(unsigned)) + 1U; char* newString = static_cast(malloc(actualLength)); if (newString == 0) { throwRuntimeError( @@ -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) @@ -249,9 +249,9 @@ Value::CZString::CZString(const CZString& other) : other.cstr_) { storage_.policy_ = (other.cstr_ - ? (other.storage_.policy_ == noDuplication + ? (static_cast(other.storage_.policy_) == noDuplication ? noDuplication : duplicate) - : other.storage_.policy_); + : static_cast(other.storage_.policy_)); storage_.length_ = other.storage_.length_; } @@ -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: @@ -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) { @@ -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; } @@ -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; } @@ -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; } @@ -986,7 +987,7 @@ 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, @@ -994,7 +995,7 @@ Value& Value::resolveReference(char const* key, char const* end) if (type_ == nullValue) *this = Value(objectValue); CZString actualKey( - key, static_cast(end-key), CZString::duplicateOnCopy); + key, static_cast(cend-key), CZString::duplicateOnCopy); ObjectValues::iterator it = value_.map_->lower_bound(actualKey); if (it != value_.map_->end() && (*it).first == actualKey) return (*it).second; @@ -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(end-key), CZString::noDuplication); + CZString actualKey(key, static_cast(cend-key), CZString::noDuplication); ObjectValues::const_iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return NULL; return &(*it).second; @@ -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 @@ -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(end-key), CZString::noDuplication); + CZString actualKey(key, static_cast(cend-key), CZString::noDuplication); ObjectValues::iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return false; @@ -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 diff --git a/src/lib_json/json_valueiterator.inl b/src/lib_json/json_valueiterator.inl index d01d3c0..b3bbc35 100644 --- a/src/lib_json/json_valueiterator.inl +++ b/src/lib_json/json_valueiterator.inl @@ -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; } // //////////////////////////////////////////////////////////////////