fix some obvious bugs

This commit is contained in:
Alain Zscheile 2023-01-08 19:17:35 +01:00
parent b4cb7fa12c
commit d2a275be39
3 changed files with 18 additions and 10 deletions

View file

@ -129,8 +129,8 @@ impl<'a> Iterator for LinearTableRef<'a> {
}
let (i, j) = self.data.split_at(self.cklen);
self.data = j;
let name = decode_location(u32::from_be_bytes(i[0..4].try_into().unwrap()));
let name = trunc_key_at0(&self.strtab[name..]);
let name = usize::try_from(u32::from_be_bytes(i[0..4].try_into().unwrap())).unwrap();
let name = trunc_key_at0(self.strtab.get(name..)?);
Some(LinearTableEntry {
name,
typ: u32::from_be_bytes(i[4..8].try_into().unwrap()),

View file

@ -9,7 +9,7 @@ struct Cli {
file: PathBuf,
/// section location
#[arg(short, long, default_value_t = 2, value_parser = maybe_hex::<u32>)]
#[arg(short, long, default_value_t = 1, value_parser = maybe_hex::<u32>)]
location: u32,
#[command(subcommand)]
@ -36,6 +36,14 @@ fn typ_to_txt(typ: u32) -> String {
}
}
fn name_to_txt(name: &[u8]) -> String {
if let Ok(name) = core::str::from_utf8(name) {
format!("{:?}", name)
} else {
format!("{:?}", name)
}
}
fn main() {
let cli = <Cli as clap::Parser>::parse();
@ -49,9 +57,9 @@ fn main() {
.expect("unable to parse table header");
println!("name\ttyp\tlocation\tmeta\trest");
for i in ltr {
println!(
"{:?}\t{}\t{:08x}\t{:08x}\t",
i.name,
print!(
"{}\t{}\t{:08x}\t{:08x}\t",
name_to_txt(i.name),
typ_to_txt(i.typ),
i.location,
i.meta,
@ -68,9 +76,9 @@ fn main() {
println!("hash\tname\ttyp\tL\tR");
for (hash, name, typ, val_l, val_r) in ht.iter() {
println!(
"{:016x}\t{:?}\t{}\t{:016x}\t{:016x}",
"{:016x}\t{}\t{}\t{:016x}\t{:016x}",
hash,
name,
name_to_txt(name),
typ_to_txt(typ),
val_l,
val_r

View file

@ -109,8 +109,8 @@ The reason this table doesn't allow more data per entry is that performance hing
magic generator type version
@ linear table:
00000010: 0000 0005 0001 0002 0000 0000 0000 0000
strtab_ln esiz ecnt reserved
00000010: 0000 0004 0002 0001 0000 0000 0000 0000
strtab_ln ecnt esi6 reserved
name type location esiz ecnt
00000020: 0000 0001 0000 0010 0000 0004 0001 0001