@@ -109,7 +109,7 @@ static inline char* duplicateAndPrefixStringValue(
109
109
JSON_ASSERT_MESSAGE (length <= (unsigned )Value::maxInt - sizeof (unsigned ) - 1U ,
110
110
" in Json::Value::duplicateAndPrefixStringValue(): "
111
111
" length too big for prefixing" );
112
- unsigned actualLength = length + sizeof (unsigned ) + 1U ;
112
+ unsigned actualLength = length + static_cast < unsigned >( sizeof (unsigned ) ) + 1U ;
113
113
char * newString = static_cast <char *>(malloc (actualLength));
114
114
if (newString == 0 ) {
115
115
throwRuntimeError (
@@ -233,14 +233,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
233
233
// Notes: policy_ indicates if the string was allocated when
234
234
// a string is stored.
235
235
236
- Value::CZString::CZString (ArrayIndex index ) : cstr_(0 ), index_(index ) {}
236
+ Value::CZString::CZString (ArrayIndex aindex ) : cstr_(0 ), index_(aindex ) {}
237
237
238
- Value::CZString::CZString (char const * str, unsigned length , DuplicationPolicy allocate)
238
+ Value::CZString::CZString (char const * str, unsigned ulength , DuplicationPolicy allocate)
239
239
: cstr_(str)
240
240
{
241
241
// allocate != duplicate
242
- storage_.policy_ = allocate;
243
- storage_.length_ = length ;
242
+ storage_.policy_ = allocate & 0x3 ;
243
+ storage_.length_ = ulength & 0x3FFFFFFF ;
244
244
}
245
245
246
246
Value::CZString::CZString (const CZString& other)
@@ -249,9 +249,9 @@ Value::CZString::CZString(const CZString& other)
249
249
: other.cstr_)
250
250
{
251
251
storage_.policy_ = (other.cstr_
252
- ? (other.storage_ .policy_ == noDuplication
252
+ ? (static_cast <DuplicationPolicy>( other.storage_ .policy_ ) == noDuplication
253
253
? noDuplication : duplicate)
254
- : other.storage_ .policy_ );
254
+ : static_cast <DuplicationPolicy>( other.storage_ .policy_ ) );
255
255
storage_.length_ = other.storage_ .length_ ;
256
256
}
257
257
@@ -313,9 +313,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
313
313
* memset( this, 0, sizeof(Value) )
314
314
* This optimization is used in ValueInternalMap fast allocator.
315
315
*/
316
- Value::Value (ValueType type ) {
317
- initBasic (type );
318
- switch (type ) {
316
+ Value::Value (ValueType vtype ) {
317
+ initBasic (vtype );
318
+ switch (vtype ) {
319
319
case nullValue:
320
320
break ;
321
321
case intValue:
@@ -480,7 +480,7 @@ void Value::swapPayload(Value& other) {
480
480
std::swap (value_, other.value_ );
481
481
int temp2 = allocated_;
482
482
allocated_ = other.allocated_ ;
483
- other.allocated_ = temp2;
483
+ other.allocated_ = temp2 & 0x1 ;
484
484
}
485
485
486
486
void Value::swap (Value& other) {
@@ -606,12 +606,12 @@ const char* Value::asCString() const {
606
606
return this_str;
607
607
}
608
608
609
- bool Value::getString (char const ** str, char const ** end ) const {
609
+ bool Value::getString (char const ** str, char const ** cend ) const {
610
610
if (type_ != stringValue) return false ;
611
611
if (value_.string_ == 0 ) return false ;
612
612
unsigned length;
613
613
decodePrefixedString (this ->allocated_ , this ->value_ .string_ , &length, str);
614
- *end = *str + length;
614
+ *cend = *str + length;
615
615
return true ;
616
616
}
617
617
@@ -810,7 +810,8 @@ bool Value::asBool() const {
810
810
case uintValue:
811
811
return value_.uint_ ? true : false ;
812
812
case realValue:
813
- return value_.real_ ? true : false ;
813
+ // This is kind of strange. Not recommended.
814
+ return (value_.real_ != 0.0 ) ? true : false ;
814
815
default :
815
816
break ;
816
817
}
@@ -958,8 +959,8 @@ const Value& Value::operator[](int index) const {
958
959
return (*this )[ArrayIndex (index )];
959
960
}
960
961
961
- void Value::initBasic (ValueType type , bool allocated) {
962
- type_ = type ;
962
+ void Value::initBasic (ValueType vtype , bool allocated) {
963
+ type_ = vtype ;
963
964
allocated_ = allocated;
964
965
comments_ = 0 ;
965
966
}
@@ -986,15 +987,15 @@ Value& Value::resolveReference(const char* key) {
986
987
}
987
988
988
989
// @param key is not null-terminated.
989
- Value& Value::resolveReference (char const * key, char const * end )
990
+ Value& Value::resolveReference (char const * key, char const * cend )
990
991
{
991
992
JSON_ASSERT_MESSAGE (
992
993
type_ == nullValue || type_ == objectValue,
993
994
" in Json::Value::resolveReference(key, end): requires objectValue" );
994
995
if (type_ == nullValue)
995
996
*this = Value (objectValue);
996
997
CZString actualKey (
997
- key, static_cast <unsigned >(end -key), CZString::duplicateOnCopy);
998
+ key, static_cast <unsigned >(cend -key), CZString::duplicateOnCopy);
998
999
ObjectValues::iterator it = value_.map_ ->lower_bound (actualKey);
999
1000
if (it != value_.map_ ->end () && (*it).first == actualKey)
1000
1001
return (*it).second ;
@@ -1012,13 +1013,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const {
1012
1013
1013
1014
bool Value::isValidIndex (ArrayIndex index) const { return index < size (); }
1014
1015
1015
- Value const * Value::find (char const * key, char const * end ) const
1016
+ Value const * Value::find (char const * key, char const * cend ) const
1016
1017
{
1017
1018
JSON_ASSERT_MESSAGE (
1018
1019
type_ == nullValue || type_ == objectValue,
1019
1020
" in Json::Value::find(key, end, found): requires objectValue or nullValue" );
1020
1021
if (type_ == nullValue) return NULL ;
1021
- CZString actualKey (key, static_cast <unsigned >(end -key), CZString::noDuplication);
1022
+ CZString actualKey (key, static_cast <unsigned >(cend -key), CZString::noDuplication);
1022
1023
ObjectValues::const_iterator it = value_.map_ ->find (actualKey);
1023
1024
if (it == value_.map_ ->end ()) return NULL ;
1024
1025
return &(*it).second ;
@@ -1062,9 +1063,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const
1062
1063
1063
1064
Value& Value::append (const Value& value) { return (*this )[size ()] = value; }
1064
1065
1065
- Value Value::get (char const * key, char const * end , Value const & defaultValue) const
1066
+ Value Value::get (char const * key, char const * cend , Value const & defaultValue) const
1066
1067
{
1067
- Value const * found = find (key, end );
1068
+ Value const * found = find (key, cend );
1068
1069
return !found ? defaultValue : *found;
1069
1070
}
1070
1071
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
1077
1078
}
1078
1079
1079
1080
1080
- bool Value::removeMember (const char * key, const char * end , Value* removed)
1081
+ bool Value::removeMember (const char * key, const char * cend , Value* removed)
1081
1082
{
1082
1083
if (type_ != objectValue) {
1083
1084
return false ;
1084
1085
}
1085
- CZString actualKey (key, static_cast <unsigned >(end -key), CZString::noDuplication);
1086
+ CZString actualKey (key, static_cast <unsigned >(cend -key), CZString::noDuplication);
1086
1087
ObjectValues::iterator it = value_.map_ ->find (actualKey);
1087
1088
if (it == value_.map_ ->end ())
1088
1089
return false ;
@@ -1127,8 +1128,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
1127
1128
ArrayIndex oldSize = size ();
1128
1129
// shift left all items left, into the place of the "removed"
1129
1130
for (ArrayIndex i = index ; i < (oldSize - 1 ); ++i){
1130
- CZString key (i);
1131
- (*value_.map_ )[key ] = (*this )[i + 1 ];
1131
+ CZString keey (i);
1132
+ (*value_.map_ )[keey ] = (*this )[i + 1 ];
1132
1133
}
1133
1134
// erase the last one ("leftover")
1134
1135
CZString keyLast (oldSize - 1 );
@@ -1144,9 +1145,9 @@ Value Value::get(const CppTL::ConstString& key,
1144
1145
}
1145
1146
#endif
1146
1147
1147
- bool Value::isMember (char const * key, char const * end ) const
1148
+ bool Value::isMember (char const * key, char const * cend ) const
1148
1149
{
1149
- Value const * value = find (key, end );
1150
+ Value const * value = find (key, cend );
1150
1151
return NULL != value;
1151
1152
}
1152
1153
bool Value::isMember (char const * key) const
0 commit comments