Use a ParseError::EndianError rather than panicking
This commit is contained in:
parent
e604816c15
commit
e1ba759253
@ -39,6 +39,7 @@ impl std::fmt::Display for File {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ParseError {
|
||||
EndianError,
|
||||
IoError(io::Error),
|
||||
InvalidMagic,
|
||||
InvalidFormat(Option<std::string::FromUtf8Error>),
|
||||
|
24
src/utils.rs
24
src/utils.rs
@ -1,40 +1,40 @@
|
||||
#[macro_export]
|
||||
macro_rules! read_u16 {
|
||||
($elf:ident, $io:ident) => ({
|
||||
($elf:ident, $io:ident) => {{
|
||||
use byteorder::{LittleEndian, BigEndian, ReadBytesExt};
|
||||
match $elf.ehdr.data {
|
||||
types::ELFDATA2LSB => { $io.read_u16::<LittleEndian>() }
|
||||
types::ELFDATA2MSB => { $io.read_u16::<BigEndian>() }
|
||||
types::ELFDATANONE => { panic!("Unable to resolve file endianness"); }
|
||||
_ => { panic!("Unable to resolve file endianness"); }
|
||||
types::ELFDATANONE => { return Err(ParseError::EndianError); }
|
||||
_ => { return Err(ParseError::EndianError); }
|
||||
}
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! read_u32 {
|
||||
($elf:ident, $io:ident) => ({
|
||||
($elf:ident, $io:ident) => {{
|
||||
use byteorder::{LittleEndian, BigEndian, ReadBytesExt};
|
||||
match $elf.ehdr.data {
|
||||
types::ELFDATA2LSB => { $io.read_u32::<LittleEndian>() }
|
||||
types::ELFDATA2MSB => { $io.read_u32::<BigEndian>() }
|
||||
types::ELFDATANONE => { panic!("Unable to resolve file endianness"); }
|
||||
_ => { panic!("Unable to resolve file endianness"); }
|
||||
types::ELFDATANONE => { return Err(ParseError::EndianError); }
|
||||
_ => { return Err(ParseError::EndianError); }
|
||||
}
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! read_u64 {
|
||||
($elf:ident, $io:ident) => ({
|
||||
($elf:ident, $io:ident) => {{
|
||||
use byteorder::{LittleEndian, BigEndian, ReadBytesExt};
|
||||
match $elf.ehdr.data {
|
||||
types::ELFDATA2LSB => { $io.read_u64::<LittleEndian>() }
|
||||
types::ELFDATA2MSB => { $io.read_u64::<BigEndian>() }
|
||||
types::ELFDATANONE => { panic!("Unable to resolve file endianness"); }
|
||||
_ => { panic!("Unable to resolve file endianness"); }
|
||||
types::ELFDATANONE => { return Err(ParseError::EndianError); }
|
||||
_ => { return Err(ParseError::EndianError); }
|
||||
}
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
||||
use std;
|
||||
|
Loading…
x
Reference in New Issue
Block a user