Skip to content

Commit cfaee09

Browse files
committed
Ensure that allocation doesn't exceed isize::MAX
1 parent 06fe691 commit cfaee09

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Layout {
8383

8484
/// Returns the layout for `a` followed by `b` and the offset of `b`.
8585
///
86-
/// This function was adapted from the currently unstable `Layout::extend()`:
86+
/// This function was adapted from the `Layout::extend()`:
8787
/// https://doc.rust-lang.org/nightly/std/alloc/struct.Layout.html#method.extend
8888
#[inline]
8989
pub(crate) const fn extend(self, other: Layout) -> Option<(Layout, usize)> {
@@ -97,7 +97,7 @@ impl Layout {
9797
// - align is 0 (implied false by is_power_of_two())
9898
// - align is not a power of 2
9999
// - size rounded up to align overflows
100-
if !new_align.is_power_of_two() || new_size > core::usize::MAX - (new_align - 1) {
100+
if !new_align.is_power_of_two() || new_size > core::isize::MAX as usize - (new_align - 1) {
101101
return None;
102102
}
103103

@@ -107,7 +107,7 @@ impl Layout {
107107

108108
/// Returns the padding after `layout` that aligns the following address to `align`.
109109
///
110-
/// This function was adapted from the currently unstable `Layout::padding_needed_for()`:
110+
/// This function was adapted from the `Layout::padding_needed_for()`:
111111
/// https://doc.rust-lang.org/nightly/std/alloc/struct.Layout.html#method.padding_needed_for
112112
#[inline]
113113
pub(crate) const fn padding_needed_for(self, align: usize) -> usize {

0 commit comments

Comments
 (0)