Skip to content

Commit 94045da

Browse files
Use unchecked_add in Layout::repeat
1 parent b135c73 commit 94045da

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/libcore/alloc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ impl Layout {
239239
// > `size`, when rounded up to the nearest multiple of `align`,
240240
// > must not overflow (i.e., the rounded value must be less than
241241
// > `usize::MAX`)
242-
let padded_size = self.size() + self.padding_needed_for(self.align());
242+
let padded_size = unsafe {
243+
crate::intrinsics::unchecked_add(self.size(), self.padding_needed_for(self.align()))
244+
};
243245
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;
244246

245247
unsafe {

0 commit comments

Comments
 (0)