Merge pull request #1349 from matthiasbeyer/libimagentryref/fixes
Fix: Allocating of buffer does not work as expected with Vec::with_ca…
This commit is contained in:
commit
3d7be3a1e0
1 changed files with 13 additions and 2 deletions
|
@ -205,8 +205,19 @@ macro_rules! make_sha_mod {
|
||||||
.open(path)
|
.open(path)
|
||||||
.map_err(RE::from)
|
.map_err(RE::from)
|
||||||
.and_then(|mut file| {
|
.and_then(|mut file| {
|
||||||
let mut buffer = Vec::with_capacity(n);
|
let mut buffer = vec![0; n];
|
||||||
let _ = file.read_exact(&mut buffer)?;
|
debug!("Allocated {} bytes", buffer.capacity());
|
||||||
|
|
||||||
|
match file.read_exact(&mut buffer) {
|
||||||
|
Ok(_) => { /* yay */ Ok(()) },
|
||||||
|
Err(e) => if e.kind() == ::std::io::ErrorKind::UnexpectedEof {
|
||||||
|
debug!("Ignoring unexpected EOF before {} bytes were read", n);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
|
||||||
let buffer = String::from_utf8(buffer)?;
|
let buffer = String::from_utf8(buffer)?;
|
||||||
$hashingimpl(buffer)
|
$hashingimpl(buffer)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue