Podger2016 / rapidjson

Automatically exported from code.google.com/p/rapidjson
0 stars 0 forks source link

Removing last member in object crashes the library #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. try to remove last member in JSON entry by calling 
object.RemoveMember("lastentry");

What is the expected output? What do you see instead?
Expected would be that this given member would be removed like the others.
What happens is that it crashes because it tries to remove last member by 
moving the last one to it's place :)

this assert on line 165 in document.h crashes it:
RAPIDJSON_ASSERT(this != &rhs);

What version of the product are you using? On what operating system?
0.1 version

Please provide any additional information below.

Original issue reported on code.google.com by toxyg...@gmail.com on 31 Jul 2012 at 12:22

GoogleCodeExporter commented 8 years ago
I've encounter this problem just now. I tried to fix it by changing code in 
RemoveMember() to 

  Member* last = data_.o.members + (data_.o.size - 1);
  if (last == m) {
    m->name.~GenericValue();
    m->value.~GenericValue();
  } else {
    m->name = last->name;
    m->value = last->value;
  }

that is, it now checks if we are removing last member and if yes, it just calls 
destructors instead of assignment operator. I'm not sure if this is correct 
fix, but so far it stopped crashing on the assertion. I have yet to run 
valgrind on it to check if this causes memory leaks.

Original comment by alex.bol...@gmail.com on 31 Jul 2012 at 9:44

GoogleCodeExporter commented 8 years ago

Original comment by milo...@gmail.com on 12 Nov 2012 at 2:25