From d9587c38d18f2ca82f29ddd77ae5f9f3163319b1 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Wed, 8 Mar 2023 09:28:11 -0800 Subject: [PATCH] types: cast to arch-specific c_char instead of i8 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: https://github.com/anakryiko/btfdump/issues/3 Signed-off-by: Andrii Nakryiko --- src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types.rs b/src/types.rs index 7a3dc1c..9cd6fda 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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; @@ -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()?) } }