Skip to content

mem::zeroed docs should be more explicit about the dangers of invalid values #46096

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

Closed
hanna-kruppe opened this issue Nov 19, 2017 · 3 comments
Closed
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. P-medium Medium priority

Comments

@hanna-kruppe
Copy link
Contributor

hanna-kruppe commented Nov 19, 2017

This function is sometimes perceived as "more safe" than mem::uninitialized for arbitrary types. For types where the all-zero bit pattern is invalid, however, it is only more safe in that the run-time consequences of the UB are likely a bit less exploitable.

While the docs do warn that it can produce invalid values, this is put in the context of "dropping those invalid values is UB". At least some of the other ways in which invalid values can cause UB should be mentioned. There's a reference to mem::uninitialized for "similar caveats", but it's tricky to apply the wording there (talking about uninitialized data) to invalid values.

Ideally I'd like to say creating invalid values is UB, period (the Nomicon already says so, and it matches mem::uninitialized being slated for deprecation) but that's of course a rather drastic measure. At minimum, there should be a hint that various ways of reading the value (matching on it, putting it in an enum, printing it) are UB with invalid values.

@kennytm kennytm added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Nov 19, 2017
@hanna-kruppe
Copy link
Contributor Author

Forgot to mention: Motivation for opening this issue was #46089

@steveklabnik steveklabnik added the P-medium Medium priority label Nov 21, 2017
@steveklabnik steveklabnik added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label May 29, 2018
@DevQps
Copy link
Contributor

DevQps commented Aug 8, 2019

@steveklabnik @rkruppe I am not sure when the original docs got changed but they seem to be improved! They also make a mention of MaybeUninit. I think we can close this issue now if you agree!

@hanna-kruppe
Copy link
Contributor Author

Yeah, this can be closed now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

4 participants