Skip to content

Commit 7e3bee6

Browse files
committed
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.
1 parent fc8b13c commit 7e3bee6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compiler/rustc_data_structures/src/sip128.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ impl SipHasher128 {
255255
// elements from spill (at most LEN - 1 bytes could have overflowed
256256
// into the spill). The memcpy call is optimized away because the size
257257
// is known. And the whole copy is optimized away for LEN == 1.
258+
let dst = self.buf.as_mut_ptr() as *mut u8;
258259
let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8;
259-
ptr::copy_nonoverlapping(src, self.buf.as_mut_ptr() as *mut u8, LEN - 1);
260+
ptr::copy_nonoverlapping(src, dst, LEN - 1);
260261

261262
// This function should only be called when the write fills the buffer.
262263
// Therefore, when LEN == 1, the new `self.nbuf` must be zero.

0 commit comments

Comments
 (0)