Fix error pointer behaviour of cJSON_ParseWithOpts() #200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is
cJSON_ParseWithOpts() doesn't set the error pointer on parse error. This differs from cJSON_Parse() and also from original behaviour.
What should be
cJSON_ParseWithOpts() should set the error pointer on parse error.
Detail
I started using cJSON at work around a year and a half ago, and wrote unit tests around that version of the code. When I updated my copy of the source with the latest code from this repo last week I noticed that my tests failed due to the change in error handling behaviour for cJSON_ParseWithOpts():
original behaviour on error
current behaviour on error
proposed behaviour on error
It makes good sense that the parse_end pointer is now updated. However it looks like a bug to fail to update the error pointer in the error case. It violates the principle of least surprise, and is also an interface change for no good reason that I can see.
My change updates the unit tests to check for the new behaviour, and updates the code to match.
I developed against master before discovering a minute ago that you need changes to go on the "develop" branch, so I submitted the merge request to develop. As will be obvious it's only the last 3 commits that are mine. My apologies for the clutter!
regards,
Robin Mallinson