Skip to content

Commit d356f35

Browse files
committed
Document SipHasher128::finish_inner safety
Revert "a" This reverts commit 6635c4d824375c39595c868a6d0fc1bf1e931d17.
1 parent c2b3deb commit d356f35

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/sip128.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,16 @@ impl SipHasher128 {
380380

381381
#[inline(always)]
382382
pub fn finish128(mut self) -> [u64; 2] {
383-
SipHasher128::finish128_inner(self.nbuf, &mut self.buf, self.state, self.processed)
383+
unsafe {
384+
SipHasher128::finish128_inner(self.nbuf, &mut self.buf, self.state, self.processed)
385+
}
384386
}
385387

388+
// A function for finishing the hashing.
389+
//
390+
// SAFETY: `buf` must be initialized up to the byte offset `nbuf`.
386391
#[inline]
387-
fn finish128_inner(
392+
unsafe fn finish128_inner(
388393
nbuf: usize,
389394
buf: &mut [MaybeUninit<u64>; BUFFER_WITH_SPILL_CAPACITY],
390395
mut state: State,
@@ -504,7 +509,9 @@ impl Hasher for SipHasher128 {
504509

505510
fn finish(&self) -> u64 {
506511
let mut buf = self.buf.clone();
507-
let [a, b] = SipHasher128::finish128_inner(self.nbuf, &mut buf, self.state, self.processed);
512+
let [a, b] = unsafe {
513+
SipHasher128::finish128_inner(self.nbuf, &mut buf, self.state, self.processed)
514+
};
508515

509516
// Combining the two halves makes sure we get a good quality hash.
510517
a.wrapping_mul(3).wrapping_add(b).to_le()

0 commit comments

Comments
 (0)