diff options
| author | Eugene Shamis <eugene.shamis@amd.com> | 2024-11-01 15:33:07 -0400 |
|---|---|---|
| committer | Eugene Shamis <eugene.shamis@amd.com> | 2024-11-04 12:36:24 -0500 |
| commit | 02a1ab807191891e888c19b4b8b54de33dba081b (patch) | |
| tree | 86688c18332a50d6f994fefdf47daeec061205aa | |
| parent | 432972cae64d736b892e7a4c8b4fe7fe0e888904 (diff) | |
| download | rust-02a1ab807191891e888c19b4b8b54de33dba081b.tar.gz rust-02a1ab807191891e888c19b4b8b54de33dba081b.zip | |
Replace checked slice indexing by unchecked to support panic-free code
Fixes #126425 Replace the potentially panicking `[]` indexing with `get_unchecked()` to prevent linking with panic-related code.
| -rw-r--r-- | library/core/src/fmt/num.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index f1540803f97..aaf429bac8e 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -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 { |
