From 6027182328c341e672b58c820777941814643a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Wed, 31 Mar 2021 17:04:14 +0200 Subject: [PATCH 1/4] Fix a layout miscalculation in alloc::RawVec --- library/alloc/src/raw_vec.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 8fa0242ca9a9f..0edcaa9ef7675 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -244,9 +244,7 @@ impl RawVec { // We have an allocated chunk of memory, so we can bypass runtime // checks to get our current layout. unsafe { - let align = mem::align_of::(); - let size = mem::size_of::() * self.cap; - let layout = Layout::from_size_align_unchecked(size, align); + let layout = Layout::array::(self.cap).unwrap_unchecked(); Some((self.ptr.cast().into(), layout)) } } From d3e2ffcbc69eadc63a7265a7902739080b9338de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 2 Aug 2021 11:34:37 +0200 Subject: [PATCH 2/4] Fix `shrink` and `capacity_from_bytes` --- library/alloc/src/raw_vec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 0edcaa9ef7675..ae1f8c0e51374 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -425,10 +425,11 @@ impl RawVec { assert!(cap <= self.capacity(), "Tried to shrink to a larger capacity"); let (ptr, layout) = if let Some(mem) = self.current_memory() { mem } else { return Ok(()) }; - let new_size = cap * mem::size_of::(); let ptr = unsafe { - let new_layout = Layout::from_size_align_unchecked(new_size, layout.align()); + // `Layout::array` cannot overflow here because it would have + // owerflown earlier when capacity was larger. + let new_layout = Layout::array::(cap).unwrap_unchecked(); self.alloc .shrink(ptr, layout, new_layout) .map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })? From fe7d7c20046c59ee91d763f5ab70aff42a73bca7 Mon Sep 17 00:00:00 2001 From: Alphyr <47725341+a1phyr@users.noreply.github.com> Date: Sat, 7 Aug 2021 18:57:48 +0200 Subject: [PATCH 3/4] Fix typo Co-authored-by: Josh Triplett --- library/alloc/src/raw_vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index ae1f8c0e51374..0ce2beb63d681 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -428,7 +428,7 @@ impl RawVec { let ptr = unsafe { // `Layout::array` cannot overflow here because it would have - // owerflown earlier when capacity was larger. + // overflowed earlier when capacity was larger. let new_layout = Layout::array::(cap).unwrap_unchecked(); self.alloc .shrink(ptr, layout, new_layout) From 5376317c7f39c41250f354d6c35858bd383d1970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Tue, 26 Oct 2021 17:40:42 +0200 Subject: [PATCH 4/4] Ignore failing test on aarch64 --- src/test/ui/sanitize/hwaddress.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/ui/sanitize/hwaddress.rs b/src/test/ui/sanitize/hwaddress.rs index bb6986740d906..b988035f75e4c 100644 --- a/src/test/ui/sanitize/hwaddress.rs +++ b/src/test/ui/sanitize/hwaddress.rs @@ -1,6 +1,9 @@ // needs-sanitizer-support // needs-sanitizer-hwaddress // +// FIXME(#83706): this test triggers errors on aarch64-gnu +// ignore-aarch64-unknown-linux-gnu +// // FIXME(#83989): codegen-units=1 triggers linker errors on aarch64-gnu // compile-flags: -Z sanitizer=hwaddress -O -g -C codegen-units=16 //