Skip to content

Commit ea24395

Browse files
committed
Add debug_asserts for the unsafe indexing in fmt::write.
1 parent d80f127 commit ea24395

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/core/src/fmt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::v1::Argument, args: &[ArgumentV
11101110
}
11111111

11121112
// Extract the correct argument
1113-
1113+
debug_assert!(arg.position < args.len());
11141114
// SAFETY: arg and args come from the same Arguments,
11151115
// which guarantees its index is always within bounds.
11161116
let value = unsafe { args.get_unchecked(arg.position) };
@@ -1124,6 +1124,7 @@ unsafe fn getcount(args: &[ArgumentV1<'_>], cnt: &rt::v1::Count) -> Option<usize
11241124
rt::v1::Count::Is(n) => Some(n),
11251125
rt::v1::Count::Implied => None,
11261126
rt::v1::Count::Param(i) => {
1127+
debug_assert!(i < args.len());
11271128
// SAFETY: cnt and args come from the same Arguments,
11281129
// which guarantees this index is always within bounds.
11291130
unsafe { args.get_unchecked(i).as_usize() }

0 commit comments

Comments
 (0)