-
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
Stack overflow for circular reference #880
Comments
Thanks for your report.
Yes, we are aware of circular references. We can handle this by iterating all items and check if there are circular references, but this is no doubt a time consuming operation. I do not like this. Feel free to tell me if you have better ideas. |
I suggest implementing a set with a tree-based structure, something like this (http://web.cs.wpi.edu/~cs2102/common/kathi-notes/set-impl-w-trees.html). You prepare a set of visited nodes. Then, while walking through the duplication, you abort if a node is already traversed. You do not need the tree to stay balanced IMO. In that case, we can use a black-red tree. I see the problem of adding such a big structure tho. It is not even C++ where you can leverage |
I noticed that cJSON does not correctly handle objects with circular references (commit
3249730
).For instance, I can have 3 objects that points each other, e.g., A->B->C->A, the function
cJSON_Duplicate
enters in a infinite recursions.Here is a simple example:
The problem seems that
cJSON_Duplicate
has no way to know if thechild
has been already processed, line 2773 in my version:I would propose a fix but I am not sure how to operate.
I see two possible solutions:
AddItem
is usedcJSON_Duplicate
or similar.Can you hint me if you were already aware of this problem, and if you plan to fix it?
The text was updated successfully, but these errors were encountered: