@@ -108,7 +108,7 @@ static inline char* duplicateAndPrefixStringValue(
108
108
JSON_ASSERT_MESSAGE (length <= (unsigned )Value::maxInt - sizeof (unsigned ) - 1U ,
109
109
" in Json::Value::duplicateAndPrefixStringValue(): "
110
110
" length too big for prefixing" );
111
- unsigned actualLength = length + sizeof (unsigned ) + 1U ;
111
+ unsigned actualLength = length + static_cast < unsigned >( sizeof (unsigned ) ) + 1U ;
112
112
char * newString = static_cast <char *>(malloc (actualLength));
113
113
if (newString == 0 ) {
114
114
throwRuntimeError (
@@ -232,14 +232,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
232
232
// Notes: policy_ indicates if the string was allocated when
233
233
// a string is stored.
234
234
235
- Value::CZString::CZString (ArrayIndex index ) : cstr_(0 ), index_(index ) {}
235
+ Value::CZString::CZString (ArrayIndex aindex ) : cstr_(0 ), index_(aindex ) {}
236
236
237
- Value::CZString::CZString (char const * str, unsigned length , DuplicationPolicy allocate)
237
+ Value::CZString::CZString (char const * str, unsigned ulength , DuplicationPolicy allocate)
238
238
: cstr_(str)
239
239
{
240
240
// allocate != duplicate
241
- storage_.policy_ = allocate;
242
- storage_.length_ = length ;
241
+ storage_.policy_ = allocate & 0x3 ;
242
+ storage_.length_ = ulength & 0x3FFFFFFF ;
243
243
}
244
244
245
245
Value::CZString::CZString (const CZString& other)
@@ -248,9 +248,9 @@ Value::CZString::CZString(const CZString& other)
248
248
: other.cstr_)
249
249
{
250
250
storage_.policy_ = (other.cstr_
251
- ? (other.storage_ .policy_ == noDuplication
251
+ ? (static_cast <DuplicationPolicy>( other.storage_ .policy_ ) == noDuplication
252
252
? noDuplication : duplicate)
253
- : other.storage_ .policy_ );
253
+ : static_cast <DuplicationPolicy>( other.storage_ .policy_ ) );
254
254
storage_.length_ = other.storage_ .length_ ;
255
255
}
256
256
@@ -312,9 +312,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
312
312
* memset( this, 0, sizeof(Value) )
313
313
* This optimization is used in ValueInternalMap fast allocator.
314
314
*/
315
- Value::Value (ValueType type ) {
316
- initBasic (type );
317
- switch (type ) {
315
+ Value::Value (ValueType vtype ) {
316
+ initBasic (vtype );
317
+ switch (vtype ) {
318
318
case nullValue:
319
319
break ;
320
320
case intValue:
@@ -478,7 +478,7 @@ void Value::swapPayload(Value& other) {
478
478
std::swap (value_, other.value_ );
479
479
int temp2 = allocated_;
480
480
allocated_ = other.allocated_ ;
481
- other.allocated_ = temp2;
481
+ other.allocated_ = temp2 & 0x1 ;
482
482
}
483
483
484
484
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
}
@@ -960,8 +961,8 @@ const Value& Value::operator[](int index) const {
960
961
return (*this )[ArrayIndex (index )];
961
962
}
962
963
963
- void Value::initBasic (ValueType type , bool allocated) {
964
- type_ = type ;
964
+ void Value::initBasic (ValueType vtype , bool allocated) {
965
+ type_ = vtype ;
965
966
allocated_ = allocated;
966
967
comments_ = 0 ;
967
968
start_ = 0 ;
@@ -990,15 +991,15 @@ Value& Value::resolveReference(const char* key) {
990
991
}
991
992
992
993
// @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 )
994
995
{
995
996
JSON_ASSERT_MESSAGE (
996
997
type_ == nullValue || type_ == objectValue,
997
998
" in Json::Value::resolveReference(key, end): requires objectValue" );
998
999
if (type_ == nullValue)
999
1000
*this = Value (objectValue);
1000
1001
CZString actualKey (
1001
- key, static_cast <unsigned >(end -key), CZString::duplicateOnCopy);
1002
+ key, static_cast <unsigned >(cend -key), CZString::duplicateOnCopy);
1002
1003
ObjectValues::iterator it = value_.map_ ->lower_bound (actualKey);
1003
1004
if (it != value_.map_ ->end () && (*it).first == actualKey)
1004
1005
return (*it).second ;
@@ -1016,13 +1017,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const {
1016
1017
1017
1018
bool Value::isValidIndex (ArrayIndex index) const { return index < size (); }
1018
1019
1019
- Value const * Value::find (char const * key, char const * end ) const
1020
+ Value const * Value::find (char const * key, char const * cend ) const
1020
1021
{
1021
1022
JSON_ASSERT_MESSAGE (
1022
1023
type_ == nullValue || type_ == objectValue,
1023
1024
" in Json::Value::find(key, end, found): requires objectValue or nullValue" );
1024
1025
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);
1026
1027
ObjectValues::const_iterator it = value_.map_ ->find (actualKey);
1027
1028
if (it == value_.map_ ->end ()) return NULL ;
1028
1029
return &(*it).second ;
@@ -1066,9 +1067,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const
1066
1067
1067
1068
Value& Value::append (const Value& value) { return (*this )[size ()] = value; }
1068
1069
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
1070
1071
{
1071
- Value const * found = find (key, end );
1072
+ Value const * found = find (key, cend );
1072
1073
return !found ? defaultValue : *found;
1073
1074
}
1074
1075
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
1081
1082
}
1082
1083
1083
1084
1084
- bool Value::removeMember (const char * key, const char * end , Value* removed)
1085
+ bool Value::removeMember (const char * key, const char * cend , Value* removed)
1085
1086
{
1086
1087
if (type_ != objectValue) {
1087
1088
return false ;
1088
1089
}
1089
- CZString actualKey (key, static_cast <unsigned >(end -key), CZString::noDuplication);
1090
+ CZString actualKey (key, static_cast <unsigned >(cend -key), CZString::noDuplication);
1090
1091
ObjectValues::iterator it = value_.map_ ->find (actualKey);
1091
1092
if (it == value_.map_ ->end ())
1092
1093
return false ;
@@ -1131,8 +1132,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
1131
1132
ArrayIndex oldSize = size ();
1132
1133
// shift left all items left, into the place of the "removed"
1133
1134
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 ];
1136
1137
}
1137
1138
// erase the last one ("leftover")
1138
1139
CZString keyLast (oldSize - 1 );
@@ -1148,9 +1149,9 @@ Value Value::get(const CppTL::ConstString& key,
1148
1149
}
1149
1150
#endif
1150
1151
1151
- bool Value::isMember (char const * key, char const * end ) const
1152
+ bool Value::isMember (char const * key, char const * cend ) const
1152
1153
{
1153
- Value const * value = find (key, end );
1154
+ Value const * value = find (key, cend );
1154
1155
return NULL != value;
1155
1156
}
1156
1157
bool Value::isMember (char const * key) const
0 commit comments