Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions fitsio/src/stringutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
use libc::{c_char, c_int, size_t};
use std::ffi::{CStr, CString};

/// Helper function converting a C string pointer to Rust String
/// Helper function converting a C string buffer to Rust String
pub fn buf_to_string(buffer: &[c_char]) -> Result<String> {
let c_str = unsafe { CStr::from_ptr(buffer.as_ptr()) };
// Safety: c_char and u8 have the same size and alignment
let bytes: &[u8] = unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const u8, buffer.len()) };
let c_str = CStr::from_bytes_until_nul(bytes)

Check failure on line 10 in fitsio/src/stringutils.rs

View workflow job for this annotation

GitHub Actions / minimal versions check

current MSRV (Minimum Supported Rust Version) is `1.58.0` but this item is stable since `1.69.0`
.map_err(|_| crate::errors::Error::Message("buffer is not null-terminated".to_string()))?;
Ok(c_str.to_str()?.to_string())
}

Expand Down
Loading