Skip to content

Conversation

M1cha
Copy link
Contributor

@M1cha M1cha commented Jun 16, 2021

No description provided.

@github-actions github-actions bot added area: API Changes to public APIs area: Tests Issues related to a particular existing or missing test labels Jun 16, 2021
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, clearly this needs a commit message to explain what's going on. It's a bug with parsing nested arrays, I guess? Just write up an example of a mis-parsed input string and a quick description of how the fix works. I frankly don't understand how this works at all.

Beyond that, some nitpicking about the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure on our stance on utf-8 embedded in C code, but I know this isn't allowed per ISO C and I'm reasonably certain one or more of the various coding standards we try to adopt makes this illegal.

Copy link
Contributor Author

@M1cha M1cha Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're right, this file used utf-8 before and I'm just following the existing style of the rest of the code.
If we wanna enforce ISO-C utf-8 rules we should add a CI check for it and fix the whole zephyr repo.
That would be out of scope for this PR though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcc at least defaults to UTF-8 as the input and string literal encoding. I don't know how this support is in other compilers. But, in this case, this is merely adding an additional test case that is similar to others. Fixing the UTF-8 aspect would be a separate effort.

lib/os/json.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not if (val) { here and skip the changes above? Seems like this is just adding code for no reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's more natural to check the pointer you're about to write to for NULL instead of some other variable.
Also, the hope is that it prevents bugs caused by future changes, e.g. if element doesn't rely on var anymore.

lib/os/json.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't pass the string in val down to decode_value(), how does it have anything to parse? Not understanding how this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, val was just passed through from the argument to this function.
val is just a pointer to the start of the parent struct so arr_parse can do offset calculations.
arr_parse is the only place where this value is actually being used and everyone else just passed it through.

@andyross
Copy link
Contributor

You answered my nitpicks, but not the core question: what does this actually fix? What were we parsing wrong before, and why?

@zephyrbot zephyrbot added the area: Base OS Base OS Library (lib/os) label Jun 17, 2021
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcc at least defaults to UTF-8 as the input and string literal encoding. I don't know how this support is in other compilers. But, in this case, this is merely adding an additional test case that is similar to others. Fixing the UTF-8 aspect would be a separate effort.

Comment on lines 366 to 367
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d3zd3z Should I do this to fix the compliance check? That looks awkward but it works.

Suggested change
.n_elements = \
1 + ZERO_OR_COMPILE_ERROR(elem_descr_len_ == 1), \
.n_elements = \
1 + \
ZERO_OR_COMPILE_ERROR( \
elem_descr_len_ == 1 \
), \

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably reasonable. This code is kind of overly deep anyway, but we're not about fixing that aspect.

@M1cha M1cha force-pushed the fix-array-array branch 3 times, most recently from 0a8bf1d to 23d70f7 Compare June 18, 2021 17:55
@M1cha M1cha requested a review from d3zd3z June 30, 2021 15:24
Previously, the first element inside the array-array didn't contain the
decoded data.

Signed-off-by: Michael Zimmermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Base OS Base OS Library (lib/os) area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON_OBJ_DESCR_ARRAY_ARRAY is dangerously broken
6 participants