-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
json: json_obj_parse will modify the input string #21967
Comments
Is this really a bug? I think this is the library working as designed. Otherwise it would have to duplicate the string. |
(Not sure why I was assigned) However, I agree with @mbolivar that this is not exactly a bug. Parsing JSON and returning an hierarchy of JSON objects is memory intensive (not to mention the manual memory allocation handling). Since Zephyr is targeting embedded devices with limited memory, parsing in-place with modifications is an acceptable compromise. If you need to parse the string twice, could you try duplicating the string first to extract information for your first step? You can release the memory for the duplicated string, and then proceed to parse the original string. |
@jhedberg I think the labels need a -bug +question and this issue can be closed. |
Describe the bug
The end
"
of string items will be changed to\0
afterjson_obj_parse
, i.e. we have a char array like this:if using
json_obj_parse
to proceed it, then it will be changed toTo Reproduce
Steps to reproduce the behavior:
json_obj_parse
Expected behavior
From my point of view,
json_obj_parse
should bewhich means the input json string should not be modified.
Impact
Sometimes we'd like to proceed a json string twice:
json_obj_descr
If
json_obj_parse
will modify string, user have to create a copy of string .Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: