-
Notifications
You must be signed in to change notification settings - Fork 13.4k
limit impls of VaArgSafe
to just types that are actually safe
#141341
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
Conversation
/// Trait which permits the allowed types to be used with [super::VaListImpl::arg]. | ||
pub unsafe trait VaArgSafe: sealed::Sealed {} | ||
|
||
unsafe impl VaArgSafe for i32 {} |
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.
Can you add a comment capturing a short form of the justification here? like "variable arguments must be promoted to at least c_int
, but Rust doesn't implicitly promote".
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 added a # Safety
section to the trait with some extra details, and comments for the (deliberately) missing implementations. Hopefully that is sufficiently clear.
This comment has been minimized.
This comment has been minimized.
8 and 16-bit integers are subject to upcasting in C, and hence are not reliably safe. users should perform their own casting and deal with the consequences
bede725
to
d8a22a2
Compare
This PR modifies cc @jieyouxu |
cool. @bors r+ rollup |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#140526 (docs: Specify that common sort functions sort in an ascending direction) - rust-lang#141230 (std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque`) - rust-lang#141341 (limit impls of `VaArgSafe` to just types that are actually safe) - rust-lang#141347 (incorrectly prefer builtin `dyn` impls :3) - rust-lang#141351 (Move -Zcrate-attr injection to just after crate root parsing) - rust-lang#141356 (lower bodies' params to thir before the body's value) - rust-lang#141357 (`unpretty=thir-tree`: don't require the final expr to be the body's value) - rust-lang#141363 (Document why we allow escaping bound vars in LTA norm) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#141341 - folkertdev:limit-VaArgSafe-impls, r=workingjubilee limit impls of `VaArgSafe` to just types that are actually safe tracking issue: rust-lang#44930 Retrieving 8- or 16-bit integer arguments from a `VaList` is not safe, because such types are subject to upcasting. See rust-lang#61275 (comment) for more detail. This PR also makes the instances of `VaArgSafe` visible in the documentation, and uses a private sealed trait to make sure users cannot create additional impls of `VaArgSafe`, which would almost certainly cause UB. r? `@workingjubilee`
tracking issue: #44930
Retrieving 8- or 16-bit integer arguments from a
VaList
is not safe, because such types are subject to upcasting. See #61275 (comment) for more detail.This PR also makes the instances of
VaArgSafe
visible in the documentation, and uses a private sealed trait to make sure users cannot create additional impls ofVaArgSafe
, which would almost certainly cause UB.r? @workingjubilee