src/backup/index: style fixup & unsafe copy removal
We can use the safe .copy_from_slice alternative in this case. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
fa17b1ce2a
commit
f93b55b057
|
@ -63,18 +63,24 @@ impl DigestListEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::io::Read for DigestListEncoder {
|
impl std::io::Read for DigestListEncoder {
|
||||||
|
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
||||||
if buf.len() < 32 { panic!("read buffer too small"); }
|
if buf.len() < 32 {
|
||||||
|
panic!("read buffer too small");
|
||||||
|
}
|
||||||
|
|
||||||
if self.pos < self.count {
|
if self.pos < self.count {
|
||||||
let mut written = 0;
|
let mut written = 0;
|
||||||
loop {
|
loop {
|
||||||
let digest = self.index.index_digest(self.pos).unwrap();
|
let digest = self.index.index_digest(self.pos).unwrap();
|
||||||
unsafe { std::ptr::copy_nonoverlapping(digest.as_ptr(), buf.as_mut_ptr().add(written), 32); }
|
buf[written..(written + 32)].copy_from_slice(digest);
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
written += 32;
|
written += 32;
|
||||||
if self.pos >= self.count { break; }
|
if self.pos >= self.count {
|
||||||
if (written + 32) >= buf.len() { break; }
|
break;
|
||||||
|
}
|
||||||
|
if (written + 32) >= buf.len() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Ok(written);
|
return Ok(written);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue