-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Strange behavior observed in cJSON_ReplaceItemInArray #821
Comments
So with the call to This is somewhat similar to #807 and probably would require a similar solution. I expect generating a copy for every insert and replace operation would not be possible without a breaking change in the API. |
I encountered this strange behavior in the API
cJSON_ReplaceItemInArray
.Here below I paste a minimal example and an explanation.
I replicated this error in the latest cJSON commit
87d8f0961a01bf09bef98ff89bae9fdec42181ee
, and compiling with these options:(some options might be redundant , sorry)
The issue appears when trying to replace an item with itself:
cJSON_ReplaceItemInArray(json, 0, json)
.What I observe is that the library generates a loop in the object graphs, thus making the final object unuseful, i.e., item[0] -> item
One of the consequence is that the
cJSON_Delete
produces stack exhaustion.This is alarming because the return value
ret_v
is1
, thus the program assumes the replacement was correct.Even though I understand this might not be the intended usage of
cJSON_ReplaceItemInArray
, we should be able to detect loops in object graphs.Another approach is to generate a copy for the
newitem
argument forcJSON_ReplaceItemInArray
.This will avoid recursions, but it might lead to memory leaks.
The text was updated successfully, but these errors were encountered: