Avoid panic on invalid uint data.
This commit is contained in:
		
							parent
							
								
									d661116580
								
							
						
					
					
						commit
						65ab524053
					
				@ -305,7 +305,11 @@ macro_rules! impl_uint_from_bytes {
 | 
			
		||||
	($name: ident) => {
 | 
			
		||||
		impl FromBytes for $name {
 | 
			
		||||
			fn from_bytes(bytes: &[u8]) -> FromBytesResult<$name> {
 | 
			
		||||
				if bytes.len() <= $name::SIZE {
 | 
			
		||||
					Ok($name::from(bytes))
 | 
			
		||||
				} else {
 | 
			
		||||
					Err(FromBytesError::DataIsTooLong)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
#![feature(op_assign_traits)]
 | 
			
		||||
#![feature(associated_consts)]
 | 
			
		||||
//! Ethcore-util library
 | 
			
		||||
//!
 | 
			
		||||
//! ### Rust version:
 | 
			
		||||
 | 
			
		||||
@ -50,6 +50,8 @@ macro_rules! construct_uint {
 | 
			
		||||
		pub struct $name(pub [u64; $n_words]);
 | 
			
		||||
 | 
			
		||||
		impl $name {
 | 
			
		||||
			pub const SIZE: usize = $n_words * 8;
 | 
			
		||||
 | 
			
		||||
			/// Conversion to u32
 | 
			
		||||
			#[inline]
 | 
			
		||||
			pub fn low_u32(&self) -> u32 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user