-
Notifications
You must be signed in to change notification settings - Fork 28
[Coding Guideline]: Ensure reads of union fields produce valid values #300
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
base: main
Are you sure you want to change the base?
[Coding Guideline]: Ensure reads of union fields produce valid values #300
Conversation
✅ Deploy Preview for scrc-coding-guidelines ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
9dc2bcd to
ea2dcf2
Compare
|
@PLeVasseur @felix91gr I did a final cleanup and this rule LGTM. Please review & approve |
iglesias
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of comments. Otherwise it was all clear. One is a question about a line I wasn't sure about and the other just a typo fix suggestion.
src/coding-guidelines/types-and-traits/gui_UnionFieldValidity.rst.inc
Outdated
Show resolved
Hide resolved
src/coding-guidelines/types-and-traits/gui_UnionFieldValidity.rst.inc
Outdated
Show resolved
Hide resolved
Alright, it goes into the queue. |
src/coding-guidelines/types-and-traits/gui_UnionFieldValidity.rst.inc
Outdated
Show resolved
Hide resolved
Hey @felix91gr -- did you take a look at this one yet? I'd like it to be reviewed before we queue it up (I'll try to make time to review some of @rcseacord's latest ones tomorrow, this included, if it's not been reviewed by you yet) |
@PLeVasseur ah, sorry! I forgot we have a Merge Queue as well. I meant it as my own task queue, my bad. I haven't reviewed it yet |
PLeVasseur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for pulling this together @manhatsu and @rcseacord
Given that adding the bibliography bit touches quite a few other things, I'd suggest backing that out of this PR if you'd like the guideline to be reviewed on its merits and merged sooner than later.
I've opened issue #306 to track the work towards the work for a bibliography.
src/coding-guidelines/types-and-traits/gui_UnionFieldValidity.rst.inc
Outdated
Show resolved
Hide resolved
0431525 to
696e633
Compare
|
There is a duplication of URL in these two documents: |
Yeah, you're right. I didn't have this implemented correctly. Duplicate URLs should be fine, what I wanted to have was for the same URL to force consistent referencing to be used. I've pushed #335 which should fix this. Please take a look at the following and rebase: |
added new guideline on unions
repaired bibliography
delete unused citations
fixing up bibliography
interim save
cleaned up
…rst.inc Co-authored-by: Fernando José <fernando.iglesiasg@gmail.com>
696e633 to
99551c2
Compare
|
I rebased this on |
PLeVasseur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somewhat a procedural review to get this in-line with current best practices as outlined in CONTRIBUTING.md.
I haven't reviewed the contents of the guideline yet.
Please update and I can then take a look through content.
| If the active field is uncertain, use explicit validity checks. | ||
|
|
||
| .. rationale:: | ||
| :id: rat_UnionFieldValidityReason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use IDs generated from ./generate_guideline_templates.py.
| Reading an invalid value is undefined behavior. | ||
| .. non_compliant_example:: | ||
| :id: non_compl_ex_UnionBool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use IDs generated from ./generate_guideline_templates.py.
| } | ||
| .. non_compliant_example:: | ||
| :id: non_compl_ex_UnionChar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use IDs generated from ./generate_guideline_templates.py.
| } | ||
|
|
||
| .. non_compliant_example:: | ||
| :id: non_compl_ex_UnionEnum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use IDs generated from ./generate_guideline_templates.py.
| } | ||
|
|
||
| .. non_compliant_example:: | ||
| :id: non_compl_ex_UnionRef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use IDs generated from ./generate_guideline_templates.py.
| This noncompliant example reads a reference from a union containing a null pointer. | ||
| A similar problem occurs when reading a misaligned pointer. | ||
|
|
||
| .. code-block:: rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.
| This compliant example tracks the active field explicitly to ensure valid reads. | ||
| .. code-block:: rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.
| This compliant solution reads from the same field that was written. | ||
| .. code-block:: rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.
| This compliant example reinterprets the value as a different types where all bit patterns are valid. | ||
| .. code-block:: rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.
| This compliant example validates bytes before reading as a constrained type. | ||
| .. code-block:: rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.
Added new guideline on unions by @rcseacord.
This is the same content as #270 but moved to the feature branch.