Skip to content

Commit

Permalink
types: cast to arch-specific c_char instead of i8
Browse files Browse the repository at this point in the history
Seems like CStr::from_ptr is expecting a pointer to c_char, not i8 (as
you could get from documentation at [0]). So cast to c_char to solve the
problem.

  [0] https://doc.rust-lang.org/std/ffi/struct.CStr.html#impl-CStr

Fixes: #3
Signed-off-by: Andrii Nakryiko <[email protected]>
  • Loading branch information
anakryiko committed Mar 8, 2023
1 parent f293137 commit d9587c3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::cmp::{max, min};
use std::ffi::CStr;
use std::ffi::{c_char, CStr};
use std::fmt;
use std::mem::size_of;

Expand Down Expand Up @@ -1535,7 +1535,7 @@ impl<'a> Btf<'a> {
}

fn get_btf_str(strs: &[u8], off: u32) -> BtfResult<&str> {
let c_str = unsafe { CStr::from_ptr(&strs[off as usize] as *const u8 as *const i8) };
let c_str = unsafe { CStr::from_ptr(&strs[off as usize] as *const u8 as *const c_char) };
Ok(c_str.to_str()?)
}
}

0 comments on commit d9587c3

Please sign in to comment.