Unrevert "Remove checked_add
in Layout::repeat
"
This commit is contained in:
parent
bfc32dd106
commit
1b0bb35ca3
1 changed files with 5 additions and 7 deletions
|
@ -241,13 +241,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> {
|
||||||
// Warning, removing the checked_add here led to segfaults in #67174. Further
|
// This cannot overflow. Quoting from the invariant of Layout:
|
||||||
// analysis in #69225 seems to indicate that this is an LTO-related
|
// > `size`, when rounded up to the nearest multiple of `align`,
|
||||||
// miscompilation, so #67174 might be able to be reapplied in the future.
|
// > must not overflow (i.e., the rounded value must be less than
|
||||||
let padded_size = self
|
// > `usize::MAX`)
|
||||||
.size()
|
let padded_size = self.size() + self.padding_needed_for(self.align());
|
||||||
.checked_add(self.padding_needed_for(self.align()))
|
|
||||||
.ok_or(LayoutErr { private: () })?;
|
|
||||||
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;
|
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue