wangxiaowei0303 / rapidjson

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

bool RemoveMember(const Ch* name) fails when object <name> is the last object. #63

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Create Json w/ two objects "a": and "b":
2.  Load the DOM and parse and navigate to root
3.  Call RemoveMember passing object "b" for member to remove.

What is the expected output? What do you see instead?

I expect to succeed and have a single object "a".
Instead I get an assert failure that copy constructor is copying
onto itself.

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

I'm not sure what version, or how to tell.
I'm compiling this for Windows (XP,Vista,7, and 8).

Please provide any additional information below.

I re-wrote RemoveMember like this and it seems to work OK.

    bool RemoveMember(const Ch* name) {
        RAPIDJSON_ASSERT(IsObject());
        if (Member* m = FindMember(name)) {
            RAPIDJSON_ASSERT(data_.o.size > 0);
            RAPIDJSON_ASSERT(data_.o.members != 0);

            if (data_.o.size > 1) {
                // Move the last one to this place
                Member* last = data_.o.members + (data_.o.size - 1);
                if (m != last)
                {
                    m->name = last->name;
                    m->value = last->value;
                }
                else
                {
                    m->name.~GenericValue();
                    m->value.~GenericValue();
                }
            }
            else {
                // Only one left, just destroy
                m->name.~GenericValue();
                m->value.~GenericValue();
            }
            --data_.o.size;
            return true;
        }
        return false;
    }

Original issue reported on code.google.com by donjacou...@gmail.com on 9 Apr 2013 at 10:01

GoogleCodeExporter commented 9 years ago
Is this a duplicate of issue 18?

Original comment by milo...@gmail.com on 10 Apr 2013 at 5:13

GoogleCodeExporter commented 9 years ago
It looks like it is.  I looked through the issues page before reporting
this issue, but since it was fixed I didn't see it.  Where should I have
looked?

-Bob

Original comment by donjacou...@gmail.com on 10 Apr 2013 at 5:33

GoogleCodeExporter commented 9 years ago
I think the one you are using may be the 0.1 version. You may download the 0.11 
version in the download page.

Original comment by milo...@gmail.com on 11 Apr 2013 at 2:45

GoogleCodeExporter commented 9 years ago
Thanks ... I updated to 0.11 and deployed.  All issues are fixed.
-Bob

Original comment by donjacou...@gmail.com on 11 Apr 2013 at 8:30