Skip to content
Permalink
Browse files

Fix disasm() lifetimes

cs_disasm allocates under the hood, so a new lifetime is created
  • Loading branch information...
tmfink committed May 14, 2018
1 parent 10265ae commit a02fc099a11603589db041f568d4126dc164cc06
Showing with 3 additions and 3 deletions.
  1. +3 −3 src/capstone.rs
@@ -184,12 +184,12 @@ impl Capstone {
}

/// Disassemble all instructions in buffer
pub fn disasm_all(&mut self, code: &[u8], addr: u64) -> CsResult<Instructions> {
pub fn disasm_all<'a>(&mut self, code: &[u8], addr: u64) -> CsResult<Instructions<'a>> {
self.disasm(code, addr, 0)
}

/// Disassemble `count` instructions in `code`
pub fn disasm_count(&mut self, code: &[u8], addr: u64, count: usize) -> CsResult<Instructions> {
pub fn disasm_count<'a>(&mut self, code: &[u8], addr: u64, count: usize) -> CsResult<Instructions<'a>> {
if count == 0 {
return Err(Error::CustomError("Invalid dissasemble count; must be > 0"));
}
@@ -199,7 +199,7 @@ impl Capstone {
/// Disassembles a `&[u8]` full of instructions.
///
/// Pass `count = 0` to disassemble all instructions in the buffer.
fn disasm(&mut self, code: &[u8], addr: u64, count: usize) -> CsResult<Instructions> {
fn disasm<'a>(&mut self, code: &[u8], addr: u64, count: usize) -> CsResult<Instructions<'a>> {
// CLAIM: Capstone::new_raw() already called init_global_state()

let mut ptr: *mut cs_insn = unsafe { mem::zeroed() };

1 comment on commit a02fc09

@earthengine

This comment has been minimized.

Copy link
Contributor

earthengine commented on a02fc09 Sep 26, 2018

This code change is WRONG: when you add a lifetime but it is not tie to any input arguments, this lifetime is useless in most cases. I wrote a post to explain this.

In sort, you need to change &mut self to &'a mut self, then you wouldn't need to add lifetime to Capstone type.

Please sign in to comment.
You can’t perform that action at this time.