mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-05 16:30:50 +02:00
Fixed iteration bug over null values.
This commit is contained in:
parent
2814f6e95b
commit
a1d6c9e66a
@ -917,6 +917,8 @@ public: // overridden from ValueArrayAllocator
|
|||||||
private:
|
private:
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
Value::ObjectValues::iterator current_;
|
Value::ObjectValues::iterator current_;
|
||||||
|
// Indicates that iterator is for a null value.
|
||||||
|
bool isNull_;
|
||||||
#else
|
#else
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
ValueIteratorBase::ValueIteratorBase()
|
ValueIteratorBase::ValueIteratorBase()
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
: current_()
|
: current_()
|
||||||
|
, isNull_( true )
|
||||||
#else
|
#else
|
||||||
# error fix me // Need to handle uninitialized iterator comparison for experimental maps
|
# error fix me // Need to handle uninitialized iterator comparison for experimental maps
|
||||||
#endif
|
#endif
|
||||||
@ -23,6 +24,7 @@ ValueIteratorBase::ValueIteratorBase()
|
|||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t )
|
ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t )
|
||||||
: current_( current )
|
: current_( current )
|
||||||
|
, isNull_( false )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -86,6 +88,15 @@ ValueIteratorBase::computeDistance( const SelfType &other ) const
|
|||||||
# ifdef JSON_USE_CPPTL_SMALLMAP
|
# ifdef JSON_USE_CPPTL_SMALLMAP
|
||||||
return current_ - other.current_;
|
return current_ - other.current_;
|
||||||
# else
|
# else
|
||||||
|
// Iterator for null value are initialized using the default
|
||||||
|
// constructor, which initialize current_ to the default
|
||||||
|
// std::map::iterator. As begin() and end() are two instance
|
||||||
|
// of the default std::map::iterator, they can not be compared.
|
||||||
|
// To allow this, we handle this comparison specifically.
|
||||||
|
if ( isNull_ && other.isNull_ )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return difference_type( std::distance( current_, other.current_ ) );
|
return difference_type( std::distance( current_, other.current_ ) );
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
@ -100,6 +111,10 @@ bool
|
|||||||
ValueIteratorBase::isEqual( const SelfType &other ) const
|
ValueIteratorBase::isEqual( const SelfType &other ) const
|
||||||
{
|
{
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
|
if ( isNull_ )
|
||||||
|
{
|
||||||
|
return other.isNull_;
|
||||||
|
}
|
||||||
return current_ == other.current_;
|
return current_ == other.current_;
|
||||||
#else
|
#else
|
||||||
if ( isArray_ )
|
if ( isArray_ )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user