bug fix bug fix bug fix WIP
This commit is contained in:
parent
b30e91b86a
commit
b17a84212f
5 changed files with 153 additions and 151 deletions
|
|
@ -35,12 +35,16 @@ impl CodeItem {
|
|||
pub fn sanity_check(&self) -> Result<()> {
|
||||
if self.tries.is_empty() && self.handlers.is_some() {
|
||||
return Err(Error::InconsistantStruct(
|
||||
"CodeItem cannot have a `handlers` value if `tries_size` is 0 (CodeItem.tries is empty)".into()
|
||||
"CodeItem cannot have a `handlers` value if `tries_size` \
|
||||
is 0 (CodeItem.tries is empty)"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if !self.tries.is_empty() && self.handlers.is_none() {
|
||||
return Err(Error::InconsistantStruct(
|
||||
"CodeItem must have a `handlers` value if `tries_size` is not 0 (CodeItem.tries not empty)".into()
|
||||
"CodeItem must have a `handlers` value if `tries_size` \
|
||||
is not 0 (CodeItem.tries not empty)"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
let mut max_addr = 0;
|
||||
|
|
@ -48,7 +52,9 @@ impl CodeItem {
|
|||
let addr = item.start_addr;
|
||||
if addr < max_addr {
|
||||
return Err(Error::InconsistantStruct(
|
||||
"try_item in a code_item must be non overlapping and sorted from low to high address".into()
|
||||
"try_item in a code_item must be non overlapping and \
|
||||
sorted from low to high address"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
max_addr = addr + (item.insn_count as u32);
|
||||
|
|
@ -121,8 +127,10 @@ impl CodeItem {
|
|||
}
|
||||
}
|
||||
if i < addresses.len() && addresses[i] < addr {
|
||||
println!("{addresses:x?}");
|
||||
return Err(Error::InconsistantStruct(format!(
|
||||
"Found an address in try block (0x{addr:x}) that does not align with an instruction"
|
||||
"Found an address in try block (0x{:x}) that does not align with an instruction",
|
||||
addresses[i]
|
||||
)));
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +178,21 @@ impl Serializable for CodeItem {
|
|||
|
||||
let mut insns = vec![];
|
||||
let mut serialized_insns_size = 0;
|
||||
while serialized_insns_size != insns_size {
|
||||
let ins = Instruction::deserialize(input)?;
|
||||
serialized_insns_size += ins.size() as u32;
|
||||
while serialized_insns_size < insns_size {
|
||||
let ins = Instruction::deserialize(input).map_err(|err| {
|
||||
Error::DeserializationError(format!(
|
||||
"Failed to deserialize instruction at 0x{serialized_insns_size:x}: {err}"
|
||||
))
|
||||
})?;
|
||||
serialized_insns_size += ins.size() as u32 / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
if serialized_insns_size != insns_size {
|
||||
return Err(Error::DeserializationError(format!(
|
||||
"Failed to deserialize instructions, expected size of {insns_size} code \
|
||||
units (16 bits), found at least {serialized_insns_size}"
|
||||
)));
|
||||
}
|
||||
if tries_size != 0 && insns_size % 2 == 1 {
|
||||
let _ = u16::deserialize(input)?;
|
||||
}
|
||||
|
|
@ -265,7 +283,8 @@ impl EncodedCatchHandlerList {
|
|||
current_offset += handler.size();
|
||||
}
|
||||
Err(Error::InconsistantStruct(format!(
|
||||
"Offset 0x{offset:x} does not match with the begining of a EncodedCatchHandler in this EncodedCatchHandlerList"
|
||||
"Offset 0x{offset:x} does not match with the begining of a \
|
||||
EncodedCatchHandler in this EncodedCatchHandlerList"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue