From f93b55b057d4090f3038208ae3cce48953019022 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 22 Aug 2019 11:30:23 +0200 Subject: [PATCH] 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 --- src/backup/index.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backup/index.rs b/src/backup/index.rs index 713f6b2d..a3ab6097 100644 --- a/src/backup/index.rs +++ b/src/backup/index.rs @@ -63,18 +63,24 @@ impl DigestListEncoder { } impl std::io::Read for DigestListEncoder { - fn read(&mut self, buf: &mut [u8]) -> Result { - if buf.len() < 32 { panic!("read buffer too small"); } + if buf.len() < 32 { + panic!("read buffer too small"); + } + if self.pos < self.count { let mut written = 0; loop { 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; written += 32; - if self.pos >= self.count { break; } - if (written + 32) >= buf.len() { break; } + if self.pos >= self.count { + break; + } + if (written + 32) >= buf.len() { + break; + } } return Ok(written); } else {