diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-06-03 22:03:21 +0200 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-06-04 17:46:36 +0200 |
| commit | 7e3bee6d8ecf2bd1270b99ea1425f594d6adaf54 (patch) | |
| tree | f453aa10e3217ac1fc341ad73007bfaf19d5aa40 /compiler/rustc_data_structures/src | |
| parent | fc8b13cb96a5b45bb7028ca0f50d1444f0f95582 (diff) | |
| download | rust-7e3bee6d8ecf2bd1270b99ea1425f594d6adaf54.tar.gz rust-7e3bee6d8ecf2bd1270b99ea1425f594d6adaf54.zip | |
Fix stacked borrows invalidation in rustc_data_structures sip128
It creates the src pointer first, which is then invalidated by a unique borrow of the destination pointer. Swap the borrows around to fix this. Found with miri.
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/sip128.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_data_structures/src/sip128.rs b/compiler/rustc_data_structures/src/sip128.rs index abd25f46ad5..90793a97ed0 100644 --- a/compiler/rustc_data_structures/src/sip128.rs +++ b/compiler/rustc_data_structures/src/sip128.rs @@ -255,8 +255,9 @@ impl SipHasher128 { // elements from spill (at most LEN - 1 bytes could have overflowed // into the spill). The memcpy call is optimized away because the size // is known. And the whole copy is optimized away for LEN == 1. + let dst = self.buf.as_mut_ptr() as *mut u8; let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8; - ptr::copy_nonoverlapping(src, self.buf.as_mut_ptr() as *mut u8, LEN - 1); + ptr::copy_nonoverlapping(src, dst, LEN - 1); // This function should only be called when the write fills the buffer. // Therefore, when LEN == 1, the new `self.nbuf` must be zero. |
