@@ -142,6 +142,7 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
142
142
143
143
let mut dest_usize = dest as * mut usize ;
144
144
let dest_end = dest. wrapping_add ( n) as * mut usize ;
145
+ let dest_end = dest_end. wrapping_sub ( 1 ) ; // the last loop iteration is handled separately
145
146
146
147
// Calculate the misalignment offset and shift needed to reassemble value.
147
148
// Since `src` is definitely not aligned, `offset` is in the range 1..WORD_SIZE.
@@ -152,7 +153,7 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
152
153
let mut src_aligned = src. wrapping_byte_sub ( offset) as * mut usize ;
153
154
let mut prev_word = load_aligned_end_partial ( src_aligned, WORD_SIZE - offset) ;
154
155
155
- while dest_usize. wrapping_add ( 1 ) < dest_end {
156
+ while dest_usize < dest_end {
156
157
src_aligned = src_aligned. wrapping_add ( 1 ) ;
157
158
let cur_word = * src_aligned;
158
159
let reassembled = if cfg ! ( target_endian = "little" ) {
@@ -257,6 +258,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
257
258
258
259
let mut dest_usize = dest as * mut usize ;
259
260
let dest_start = dest. wrapping_sub ( n) as * mut usize ; // we're moving towards the start
261
+ let dest_start = dest_start. wrapping_add ( 1 ) ; // the last loop iteration is handled separately
260
262
261
263
// Calculate the misalignment offset and shift needed to reassemble value.
262
264
// Since `src` is definitely not aligned, `offset` is in the range 1..WORD_SIZE.
@@ -267,7 +269,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
267
269
let mut src_aligned = src. wrapping_byte_sub ( offset) as * mut usize ;
268
270
let mut prev_word = load_aligned_partial ( src_aligned, offset) ;
269
271
270
- while dest_start. wrapping_add ( 1 ) < dest_usize {
272
+ while dest_start < dest_usize {
271
273
src_aligned = src_aligned. wrapping_sub ( 1 ) ;
272
274
let cur_word = * src_aligned;
273
275
let reassembled = if cfg ! ( target_endian = "little" ) {
0 commit comments