Skip to content

Commit

Permalink
fix invalid ptr caused by dropping InstructionTextToken prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed Jun 4, 2024
1 parent def0569 commit f0e6121
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rust/src/disassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ impl InstructionTextToken {
mem::transmute(raw)
}

pub(crate) fn into_raw(self) -> BNInstructionTextToken {
mem::ManuallyDrop::new(self).0
}

pub fn new(text: &str, contents: InstructionTextTokenContents) -> Self {
let (value, address) = match contents {
InstructionTextTokenContents::Integer(v) => (v, 0),
Expand Down Expand Up @@ -378,7 +382,7 @@ impl From<&Vec<&str>> for DisassemblyTextLine {
fn from(string_tokens: &Vec<&str>) -> Self {
let mut tokens: Box<[BNInstructionTextToken]> = string_tokens
.iter()
.map(|&token| InstructionTextToken::new(token, InstructionTextTokenContents::Text).0)
.map(|&token| InstructionTextToken::new(token, InstructionTextTokenContents::Text).into_raw())
.collect();

// let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nighly feature
Expand Down

0 comments on commit f0e6121

Please sign in to comment.