-
Notifications
You must be signed in to change notification settings - Fork 130
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
Adding a zeroize function for flat types #1045
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b62b6c
added zeroize_flat_type()
nstilt1 d4999a5
restricted the method for Sized types and ammended the safety note
nstilt1 b42151d
fmt again :(
nstilt1 4801c84
revised zeroize_flat_type()
nstilt1 aace15e
fmt :|
nstilt1 8ab3c8b
removed an invalid safety comment
nstilt1 9961905
Revert "removed an invalid safety comment"; was confused for a moment
nstilt1 4524200
revised docs
nstilt1 2548228
removed colon from safety section :/
nstilt1 9fdd1cd
revised safety docs and added examples
nstilt1 dc91cc2
add no_run for the bad example
nstilt1 92d89e3
revised docs some more
nstilt1 2ff71ab
typo
nstilt1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 think it would be good to add something here about requiring that the bit pattern of all zeros must be valid for the type
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 do not think this requirement is needed for this function. We just need to mention that the function may leave the memory in a state invalid for type
T
.In other words, I think (but not 100% sure) that the following code is safe:
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'm not really clear on if that's allowed or not: rust-lang/unsafe-code-guidelines#394
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.
Notably it seems like it would be UB with
drop_in_place
orManuallyDrop::drop
which both permit access to the value after running theDrop
implThere 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.
Both
drop_in_place
andManuallyDrop::drop
areunsafe
, so it should not be a problem. PerManuallyDrop::drop
docs:For now, we probably should write about validity (with
NonZeroU32
as a counter-example), but mention that zeroized state is allowed to break safety invariants of the type.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.
Sure, that sounds good
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.
Okay. Feel free to make any changes