Skip to content

Commit cff72f9

Browse files
committed
Use ptr::read_unaligned() in specialized memcmp to please miri
1 parent b327ff8 commit cff72f9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/memcmp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub unsafe fn memcmp2(left: *const u8, right: *const u8, n: usize) -> bool {
1919
debug_assert_eq!(n, 2);
2020
let left = left.cast::<u16>();
2121
let right = right.cast::<u16>();
22-
*left == *right
22+
left.read_unaligned() == right.read_unaligned()
2323
}
2424

2525
#[inline]
@@ -33,7 +33,7 @@ pub unsafe fn memcmp4(left: *const u8, right: *const u8, n: usize) -> bool {
3333
debug_assert_eq!(n, 4);
3434
let left = left.cast::<u32>();
3535
let right = right.cast::<u32>();
36-
*left == *right
36+
left.read_unaligned() == right.read_unaligned()
3737
}
3838

3939
#[inline]
@@ -59,7 +59,7 @@ pub unsafe fn memcmp8(left: *const u8, right: *const u8, n: usize) -> bool {
5959
debug_assert_eq!(n, 8);
6060
let left = left.cast::<u64>();
6161
let right = right.cast::<u64>();
62-
*left == *right
62+
left.read_unaligned() == right.read_unaligned()
6363
}
6464

6565
#[inline]

0 commit comments

Comments
 (0)