#30 Working with parsed arrays triggers assert.

closed
nobody
None
5
2012-03-10
2012-02-24
Anonymous
No

The code below results in an assert using 7.5.0 build for Debug with JSON_LIBRARY define commented out in JSONOptions.h.

JSONNode testArray(JSON_ARRAY);
testArray.set_name("Test");
testArray.push_back(JSONNode("", "One"));
testArray.push_back(JSONNode("", "Two"));

std::string jsonStr = testArray.write_formatted();

// String generated is "["One","Two"]"

JSONNode parsedArrayNode = libjson::parse(jsonStr);

// This asserts
std::string jsonStr2 = parsedArrayNode.write_formatted();

// Or if above write_formmatted() call is taken out, the following also assert
JSONNode::const_iterator parsedNode = parsedArrayNode.begin();
while (parsedNode != parsedArrayNode.end())
{
++parsedNode;
}

Stack trace:

std::_Debug_message(const wchar_t * message, const wchar_t * file, unsigned int line) Line 15 C++
std::_String_const_iterator<char,std::char_traits<char>,std::allocator<char> >::operator*() Line 78 + 0x11 bytes C++
JSONWorker::FindNextRelevant<58>(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & value_t, const unsigned int pos) Line 144 + 0x26 bytes C++
JSONWorker::DoArray(const internalJSONNode * parent, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & value_t) Line 653 + 0xb bytes C++
internalJSONNode::FetchArray() Line 186 + 0x10 bytes C++
internalJSONNode::Fetch() Line 243 C++
internalJSONNode::Write(unsigned int indent, bool arrayChild, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & output) Line 213 C++
JSONNode::write_formatted(unsigned int approxsize) Line 954 C++

Discussion

  • Jonathan Wallace

    This is due to a bug that has been fixed in the next version. Hopefully I will release it by the end of the day today.

    In the mean time you can change JSONWorker.cpp line 144 from

    for (json_string::const_iterator p = start + pos; *p; ++p){

    to

    for (json_string::const_iterator p = start + pos; p != value_t.end(); ++p){

     
  • Jonathan Wallace

    • status: open --> closed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks