Skip to content

Commit efc4f08

Browse files
committed
32-bit compat
1 parent 7439807 commit efc4f08

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

src/patch.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,22 @@ pub fn patch<T: Read>(old: &[u8], patch: &mut T, new: &mut Vec<u8>) -> io::Resul
5959
return Err(io::ErrorKind::UnexpectedEof.into());
6060
}
6161

62-
let mix_slice = new
63-
.get_mut(
64-
mix_start
65-
..mix_start
66-
.checked_add(mix_len)
67-
.ok_or(io::Error::from(io::ErrorKind::InvalidData))?,
68-
)
69-
.ok_or(io::ErrorKind::UnexpectedEof)?;
70-
let old_slice = old
71-
.get(
72-
oldpos
73-
..oldpos
74-
.checked_add(mix_len)
75-
.ok_or(io::Error::from(io::ErrorKind::InvalidData))?,
76-
)
77-
.ok_or(io::ErrorKind::UnexpectedEof)?;
78-
for (n, o) in mix_slice.iter_mut().zip(old_slice) {
79-
*n = n.wrapping_add(*o);
62+
let mix_end = mix_start.checked_add(mix_len).ok_or(io::ErrorKind::InvalidData)?;
63+
let mix_slice = new.get_mut(mix_start..mix_end).ok_or(io::ErrorKind::UnexpectedEof)?;
64+
65+
let oldpos_end = oldpos.checked_add(mix_len).ok_or(io::ErrorKind::InvalidData)?;
66+
let old_slice = old.get(oldpos ..oldpos_end).ok_or(io::ErrorKind::UnexpectedEof)?;
67+
68+
for (n, o) in mix_slice.iter_mut().zip(old_slice.iter().copied()) {
69+
*n = n.wrapping_add(o);
8070
}
8171

8272
// Adjust pointers
8373
oldpos += mix_len;
8474
oldpos = (oldpos as i64)
8575
.checked_add(seek_len)
86-
.ok_or(io::Error::from(io::ErrorKind::InvalidData))? as usize;
76+
.and_then(|n| usize::try_from(n).ok())
77+
.ok_or(io::ErrorKind::InvalidData)?;
8778
}
8879
}
8980

0 commit comments

Comments
 (0)