Skip to content

Commit

Permalink
Fix data tooltip panic
Browse files Browse the repository at this point in the history
Prevents panicing when attempting to display the data tooltip for a symbol that is too large by just using as many bytes as needed from the begging of the symbol.
  • Loading branch information
SquareMan committed Oct 15, 2024
1 parent 72ea1c8 commit 462453c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions objdiff-core/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ pub enum DataType {

impl DataType {
pub fn display_bytes<Endian: ByteOrder>(&self, bytes: &[u8]) -> Option<String> {
if self.required_len().is_some_and(|l| bytes.len() < l) {
let Some(required_len) = self.required_len() else {
return None;
}
};
// TODO: For symbols larger than their data type, we should probably support
// using the relocation's relative offset to read the bytes.
let bytes = bytes.get(0..required_len)?;

match self {
DataType::Int8 => {
Expand Down

0 comments on commit 462453c

Please sign in to comment.