Skip to content

Commit

Permalink
[Fix] fix ffi::WasmEdge_String to String
Browse files Browse the repository at this point in the history
Signed-off-by: csh <[email protected]>
  • Loading branch information
L-jasmine committed Oct 31, 2023
1 parent 2ffdbb0 commit 9c95c51
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/wasmedge-sys/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl From<WasmEdgeString> for &std::ffi::CStr {

impl From<&ffi::WasmEdge_String> for String {
fn from(s: &ffi::WasmEdge_String) -> Self {
let cstr: &std::ffi::CStr = s.into();
cstr.to_string_lossy().into_owned()
let cstr = unsafe { std::slice::from_raw_parts(s.Buf as *mut u8, s.Length as usize) };
String::from_utf8(cstr.to_vec()).unwrap_or_default()
}
}
impl From<&ffi::WasmEdge_String> for &std::ffi::CStr {
Expand Down

0 comments on commit 9c95c51

Please sign in to comment.