Menu

#36 BUG: iterators - ValueIteratorBase::isEqual( const SelfType

0.5.0
closed-fixed
nobody
Value (7)
5
2015-03-06
2011-07-28
ghostd0g
No

hello,

since my mailing reports were not accepted (yet), i try to post my problem from february 2011 here too!
back then i decided to use your library but got runtime errors on iterating through all the elements.
the end-loop-condition is never met and therefore crashes.
i debugged it and it seems there is a bug in the isequal check for end().

from "json_valueiterator.inl"

bool
ValueIteratorBase::isEqual( const SelfType &other ) const
{
#ifndef JSON_VALUE_USE_INTERNAL_MAP
if ( isNull_ )
{
return other.isNull_;
}
return current_ == other.current_;
#else
.....
#endif
}

i think the problem is in
void ValueIteratorBase::increment()
not setting
isNull_ = true;
and then failing at the isEqual method.
but since i cannot check there if the inside map interator is end() and then setting isNull_,
i am out of ideas right now.
i disabled the if isNull check in the isEqual method for now. so the actual interators of the internal
map are compared. this works, but i am not sure if this does have any side effects.
anyway, i thought i should let you know.
maybe you can check this and if it really is a bug, fix it.

hope this helps!
best regards,

Dietmar Suoch

---

my test code:

Json::Value jsonRoot;
Json::Reader jsonReader;

//blah blah ... parsing from stream -> OK.
//jsonRoot.size() != 0

Json::ValueIterator it; //or const
for (it = jsonRoot.begin(); it != jsonRoot.end(); ++it) //or it++
{
//crashes after
}

my input data:
{
"item1" :
{
"visible" : true
},
"item2" :
{
"visible" : true
},
"item4" :
{
"visible" : true
},
"item" :
{
"visible" : true
}
}

my build environment:
i am using revision 156 from the repository.
i did not do any config/install/make. i just use it in my MSVC solution.
build environment: visual studio 2009, windows xp sp3, x86, 32bit

Discussion

  • Marcel Parnas

    Marcel Parnas - 2011-09-15

    Try this instead:

    Json::ValueIterator it; //or const
    for (it = jsonRoot.begin(); jsonRoot.end() != it; ++it) //or it++
    {
    //doesn't crash
    }

     
  • ghostd0g

    ghostd0g - 2011-09-16

    uhm, really? this should be the solution?
    i have not tried it and i believe you that it works.
    i have solved or circumvented it myself (in a different way),
    but i thought the purpose of reporting issues is to
    improve software quality, not learn about some arcane tricks.
    sorry, this just seems bad quality to me ...

     
  • axx1611

    axx1611 - 2012-12-05

    i got this problem too...
    can someone fix it?

     
  • axx1611

    axx1611 - 2012-12-05

    i got this problem too...
    can someone fix it?

    i think these code can help:

    ValueConstIterator &
    ValueConstIterator::operator =( const ValueIteratorBase &other )
    {
    isNull_ = other.isNull_
    copy( other );
    return *this;
    }

     
  • Christopher Dunn

    The unit-test IteratorTest/distance shows this to be fixed at: https://github.com/open-source-parsers/jsoncpp/

     
  • Christopher Dunn

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,3 @@
    -
     hello,
    
     since my mailing reports were not accepted \(yet\), i try to post my problem from february 2011 here too\!
    
    • status: open --> closed-fixed
    • Group: --> 0.5.0
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.