Skip to content

Commit

Permalink
Fix - signed_off_str (#550)
Browse files Browse the repository at this point in the history
* Adjusts offset of memory access in disassembler tests.

* Fixes minimal negative overflow in signed_off_str().
  • Loading branch information
Lichtso authored Dec 29, 2023
1 parent 2e48d19 commit 179a0f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn byteswap_str(name: &str, insn: &ebpf::Insn) -> String {
#[inline]
fn signed_off_str(value: i16) -> String {
if value < 0 {
format!("-{:#x}", -value)
format!("-{:#x}", -(value as isize))
} else {
format!("+{value:#x}")
}
Expand Down
12 changes: 6 additions & 6 deletions tests/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,22 @@ fn test_lddw() {
// Example for InstructionType::LoadReg.
#[test]
fn test_ldxdw() {
disasm!("entrypoint:\n ldxdw r1, [r2+0x3]\n");
disasm!("entrypoint:\n ldxdw r1, [r2-0x3]\n");
disasm!("entrypoint:\n ldxdw r1, [r2+0x7999]\n");
disasm!("entrypoint:\n ldxdw r1, [r2-0x8000]\n");
}

// Example for InstructionType::StoreImm.
#[test]
fn test_sth() {
disasm!("entrypoint:\n sth [r1+0x2], 3\n");
disasm!("entrypoint:\n sth [r1-0x2], 3\n");
disasm!("entrypoint:\n sth [r1+0x7999], 3\n");
disasm!("entrypoint:\n sth [r1-0x8000], 3\n");
}

// Example for InstructionType::StoreReg.
#[test]
fn test_stxh() {
disasm!("entrypoint:\n stxh [r1+0x2], r3\n");
disasm!("entrypoint:\n stxh [r1-0x2], r3\n");
disasm!("entrypoint:\n stxh [r1+0x7999], r3\n");
disasm!("entrypoint:\n stxh [r1-0x8000], r3\n");
}

// Test all supported AluBinary mnemonics.
Expand Down

0 comments on commit 179a0f9

Please sign in to comment.