From dbf74b770228b0cec9feb3b9a8eba059f6545f0e Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 24 Sep 2022 17:16:51 +0900 Subject: [PATCH 1/2] Ensure that allocation doesn't exceed isize::MAX --- src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 189e9af..ebaf752 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -83,7 +83,7 @@ impl Layout { /// Returns the layout for `a` followed by `b` and the offset of `b`. /// - /// This function was adapted from the currently unstable `Layout::extend()`: + /// This function was adapted from the `Layout::extend()`: /// https://doc.rust-lang.org/nightly/std/alloc/struct.Layout.html#method.extend #[inline] pub(crate) const fn extend(self, other: Layout) -> Option<(Layout, usize)> { @@ -97,7 +97,7 @@ impl Layout { // - align is 0 (implied false by is_power_of_two()) // - align is not a power of 2 // - size rounded up to align overflows - if !new_align.is_power_of_two() || new_size > core::usize::MAX - (new_align - 1) { + if !new_align.is_power_of_two() || new_size > core::isize::MAX as usize - (new_align - 1) { return None; } @@ -107,7 +107,7 @@ impl Layout { /// Returns the padding after `layout` that aligns the following address to `align`. /// - /// This function was adapted from the currently unstable `Layout::padding_needed_for()`: + /// This function was adapted from the `Layout::padding_needed_for()`: /// https://doc.rust-lang.org/nightly/std/alloc/struct.Layout.html#method.padding_needed_for #[inline] pub(crate) const fn padding_needed_for(self, align: usize) -> usize { From 5834856cf9e654c5835b307626b03fc92be76c55 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 24 Sep 2022 17:18:56 +0900 Subject: [PATCH 2/2] Use MAX associated constant ``` warning: use of constant `std::isize::MAX` that will be deprecated in a future Rust version: replaced by the `MAX` associated constant on this type --> src/utils.rs:100:68 | 100 | if !new_align.is_power_of_two() || new_size > core::isize::MAX as usize - (new_align - 1) { | ^^^ | = note: requested on the command line with `-W deprecated-in-future` warning: use of associated function `core::num::::max_value` that will be deprecated in a future Rust version: replaced by the `MAX` associated constant on this type --> src/raw.rs:313:47 | 313 | ... if state > isize::max_value() as usize { | ^^^^^^^^^ warning: use of associated function `core::num::::max_value` that will be deprecated in a future Rust version: replaced by the `MAX` associated constant on this type --> src/raw.rs:343:27 | 343 | if state > isize::max_value() as usize { | ``` --- src/raw.rs | 4 ++-- src/utils.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/raw.rs b/src/raw.rs index bb031da..ec2a6ec 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -310,7 +310,7 @@ where // If the task is not running, now is the time to schedule. if state & RUNNING == 0 { // If the reference count overflowed, abort. - if state > isize::max_value() as usize { + if state > isize::MAX as usize { abort(); } @@ -340,7 +340,7 @@ where let state = (*raw.header).state.fetch_add(REFERENCE, Ordering::Relaxed); // If the reference count overflowed, abort. - if state > isize::max_value() as usize { + if state > isize::MAX as usize { abort(); } diff --git a/src/utils.rs b/src/utils.rs index ebaf752..5c2170c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -97,7 +97,7 @@ impl Layout { // - align is 0 (implied false by is_power_of_two()) // - align is not a power of 2 // - size rounded up to align overflows - if !new_align.is_power_of_two() || new_size > core::isize::MAX as usize - (new_align - 1) { + if !new_align.is_power_of_two() || new_size > isize::MAX as usize - (new_align - 1) { return None; }