Skip to content

Commit

Permalink
x86iced: fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl authored and trufae committed May 8, 2024
1 parent f912df6 commit a88eecf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions x86iced/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[allow(dead_code)]
mod r2api_ext;

use iced_x86::{Decoder, DecoderOptions, Formatter, GasFormatter, Instruction, IntelFormatter, MasmFormatter};
use iced_x86::{
Decoder, DecoderOptions, Formatter, GasFormatter, Instruction, IntelFormatter, MasmFormatter,
};
use std::ffi::{c_char, c_int, c_void, CStr};
use std::ptr::{null, null_mut};

Expand All @@ -19,7 +21,7 @@ unsafe fn r2c_strdup(s: &str) -> *mut c_char {
let out_ptr = libc::malloc(s.len() + 1) as *mut c_char;
assert!(!out_ptr.is_null(), "malloc failed");
let out = std::slice::from_raw_parts_mut(out_ptr, s.len() + 1);
out.copy_from_slice(std::mem::transmute::<&[u8], &[c_char]>(s.as_bytes()));
out[..s.len()].copy_from_slice(std::mem::transmute::<&[u8], &[c_char]>(s.as_bytes()));
out[s.len()] = 0;
out_ptr
}
Expand Down

0 comments on commit a88eecf

Please sign in to comment.