File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -264,8 +264,18 @@ pub struct ArgumentV1<'a> {
264264// could have been miscompiled. In practice, we never call as_usize on non-usize
265265// containing data (as a matter of static generation of the formatting
266266// arguments), so this is merely an additional check.
267+ //
268+ // We primarily want to ensure that the function pointer at `USIZE_MARKER` has
269+ // an address corresponding *only* to functions that also take `&usize` as their
270+ // first argument. The read_volatile here ensures that we can safely ready out a
271+ // usize from the passed reference and that this address does not point at a
272+ // non-usize taking function.
267273#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
268- static USIZE_MARKER : fn ( & usize , & mut Formatter < ' _ > ) -> Result = |_, _| loop { } ;
274+ static USIZE_MARKER : fn ( & usize , & mut Formatter < ' _ > ) -> Result = |ptr, _| {
275+ // SAFETY: ptr is a reference
276+ let _v: usize = unsafe { crate :: ptr:: read_volatile ( ptr) } ;
277+ loop { }
278+ } ;
269279
270280impl < ' a > ArgumentV1 < ' a > {
271281 #[ doc( hidden) ]
You can’t perform that action at this time.
0 commit comments