mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-03 13:37:37 +00:00
Remove checked_add
in Layout::repeat
This commit is contained in:
parent
3ff17e7c5f
commit
a983e0590a
@ -239,8 +239,11 @@ impl Layout {
|
|||||||
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
|
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
|
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
|
||||||
let padded_size = self.size().checked_add(self.padding_needed_for(self.align()))
|
// This cannot overflow. Quoting from the invariant of Layout:
|
||||||
.ok_or(LayoutErr { private: () })?;
|
// > `size`, when rounded up to the nearest multiple of `align`,
|
||||||
|
// > must not overflow (i.e., the rounded value must be less than
|
||||||
|
// > `usize::MAX`)
|
||||||
|
let padded_size = self.size() + self.padding_needed_for(self.align());
|
||||||
let alloc_size = padded_size.checked_mul(n)
|
let alloc_size = padded_size.checked_mul(n)
|
||||||
.ok_or(LayoutErr { private: () })?;
|
.ok_or(LayoutErr { private: () })?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user