diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-11 10:10:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-11 10:10:47 +0100 |
| commit | b7683282425848d4edcb237aa1b2d4d9894e4bb3 (patch) | |
| tree | 8c2790e6cf298f909545d55cb696a0528321f101 | |
| parent | 96b288f593b67f535175b0fa82e81658b5a3e65d (diff) | |
| parent | a983e0590a43ed8b0f60417828efd4e79b51f494 (diff) | |
| download | rust-b7683282425848d4edcb237aa1b2d4d9894e4bb3.tar.gz rust-b7683282425848d4edcb237aa1b2d4d9894e4bb3.zip | |
Rollup merge of #67174 - kraai:remove-checked_add, r=rkruppe
Remove `checked_add` in `Layout::repeat`
| -rw-r--r-- | src/libcore/alloc.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 4cfd6527deb..5c24e3d8f5d 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -239,8 +239,11 @@ impl Layout { #[unstable(feature = "alloc_layout_extra", issue = "55724")] #[inline] pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> { - let padded_size = self.size().checked_add(self.padding_needed_for(self.align())) - .ok_or(LayoutErr { private: () })?; + // This cannot overflow. Quoting from the invariant of Layout: + // > `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) .ok_or(LayoutErr { private: () })?; |
