Skip to content

Commit

Permalink
Replace checked slice indexing by unchecked to support panic-free code
Browse files Browse the repository at this point in the history
Fixes rust-lang#126425

Replace the potentially panicking `[]` indexing with `get_unchecked()`
to prevent linking with panic-related code.
  • Loading branch information
Eugene Shamis committed Nov 4, 2024
1 parent 84fae7e commit 581aa8d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ unsafe trait GenericRadix: Sized {
};
}
}
let buf = &buf[curr..];
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented,
// so it is always in bounds.
let buf = unsafe { buf.get_unchecked(curr..) };
// SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be
// valid UTF-8
let buf = unsafe {
Expand Down

0 comments on commit 581aa8d

Please sign in to comment.