Skip to content

Commit

Permalink
Updated SAFETY comment to address underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Shamis committed Nov 4, 2024
1 parent 581aa8d commit 47f60d7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ unsafe trait GenericRadix: Sized {
};
}
}
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented,
// so it is always in bounds.
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented, so it can't overflow. It is
// decremented exactly once for each digit. Since u128 is the widest fixed width integer format dupported,
// the maximum number of digits (bits) is 128 for base-2, so `curr` won't underflow as well.
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
Expand Down

0 comments on commit 47f60d7

Please sign in to comment.