Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47f60d7

Browse files
author
Eugene Shamis
committedNov 4, 2024
Updated SAFETY comment to address underflow
1 parent 581aa8d commit 47f60d7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎core/src/fmt/num.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ unsafe trait GenericRadix: Sized {
8888
};
8989
}
9090
}
91-
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented,
92-
// so it is always in bounds.
91+
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented, so it can't overflow. It is
92+
// decremented exactly once for each digit. Since u128 is the widest fixed width integer format dupported,
93+
// the maximum number of digits (bits) is 128 for base-2, so `curr` won't underflow as well.
9394
let buf = unsafe { buf.get_unchecked(curr..) };
9495
// SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be
9596
// valid UTF-8

0 commit comments

Comments
 (0)
Failed to load comments.