Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cJSON_DetachItemViaPointer on last item leaves broken list structure #443

Closed
antcodd opened this issue Mar 11, 2020 · 3 comments
Closed

Comments

@antcodd
Copy link

antcodd commented Mar 11, 2020

cJSON_Detach* functions are not working correctly when removing the last item in the list, leaving the item still partially in the object/array. This causes major problems if moving the object to another place in the tree.

It looks like cJSON_DetachItemViaPointer is not clearing parent->child->prev if the item is an array because item->next is NULL when it is the last item in the list.

p *parent
$109 = {next = 0x0, prev = 0x89fde0, child = 0x89fe80, type = 576, valuestring = 0x0, valueint = 0, valuedouble = 0, 
  string = 0x7ffff6a51aac "parent"}

p *parent->child
$110 = {next = 0x89fed0, prev = 0x8a1160, child = 0x0, type = 8, valuestring = 0x0, valueint = 1234, valuedouble = 1234, 
  string = 0x81bc00 "item_one"}
cJSON_DetachItemViaPointer(parent, item_two);
p *parent->child
$111 = {next = 0x89fed0, prev = 0x8a1160, child = 0x0, type = 8, valuestring = 0x0, valueint = 1234, valuedouble = 1234, 
  string = 0x81bc00 "item_one"}

p *parent->child->prev
$112 = {next = 0x0, prev = 0x0, child = 0x0, type = 16, valuestring = 0x8a11b0 "bar", valueint = 0, valuedouble = 0, 
  string = 0x8a11d0 "item_two"}

This may have been introduced by #430?

@Alanscut
Copy link
Collaborator

@antcodd Thanks your report and investigation, I will revert PR #430, and try a feasible way to improve this as soon as possible.

@Alanscut
Copy link
Collaborator

hi @antcodd , would you mind to review and verify #448 ?

@Alanscut
Copy link
Collaborator

fixed by #448

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants