Avoid panicking on oversize u64.

This commit is contained in:
Gav Wood 2016-01-12 00:10:47 +01:00
parent 65ab524053
commit 48fbf24e21

View File

@ -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)
} }
} }
} }