Merge pull request #37 from gavofyork/gav
Avoid panicking on oversize u64.
This commit is contained in:
commit
584bcda7d5
@ -264,7 +264,7 @@ impl FromBytes for u64 {
|
|||||||
fn from_bytes(bytes: &[u8]) -> FromBytesResult<u64> {
|
fn from_bytes(bytes: &[u8]) -> FromBytesResult<u64> {
|
||||||
match bytes.len() {
|
match bytes.len() {
|
||||||
0 => Ok(0),
|
0 => Ok(0),
|
||||||
l => {
|
l @ 1...8 => {
|
||||||
let mut res = 0u64;
|
let mut res = 0u64;
|
||||||
for i in 0..l {
|
for i in 0..l {
|
||||||
let shift = (l - 1 - i) * 8;
|
let shift = (l - 1 - i) * 8;
|
||||||
@ -272,6 +272,7 @@ impl FromBytes for u64 {
|
|||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
_ => Err(FromBytesError::DataIsTooLong)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user