From 1195e6fe7ec9db0aafdadaceac9290c80ba4eb50 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 10 Jan 2020 02:29:27 -0800 Subject: impl yaxpeax-arch instruction/decode interface also fix panic on some immediate display in debug builds --- src/display.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/display.rs') diff --git a/src/display.rs b/src/display.rs index 036fb28..994880a 100644 --- a/src/display.rs +++ b/src/display.rs @@ -16,7 +16,7 @@ impl fmt::Display for Instruction { (Some(Operand::Reg(a)), Some(Operand::Reg(b)), Some(Operand::Imm(offs))) => { if a == b { if offs < 0 { - return write!(f, "b $-{:#x}", -offs); + return write!(f, "b $-{:#x}", offs.wrapping_neg()); } else { return write!(f, "b $+{:#x}", offs); } @@ -44,7 +44,7 @@ impl fmt::Display for Instruction { } } else if let Operand::Imm(imm) = op { if *imm < 0 { - return write!(f, "-{:#x}", -imm); + return write!(f, "-{:#x}", imm.wrapping_neg()); } else { return write!(f, "{:#x}", imm); } @@ -110,7 +110,7 @@ impl fmt::Display for Operand { write!(f, "({})", name) } else { if *offs < 0 { - write!(f, "-{:#x}({})", -offs, name) + write!(f, "-{:#x}({})", offs.wrapping_neg(), name) } else { write!(f, "{:#x}({})", offs, name) } -- cgit v1.1