Reads a C-style string from memory, stopping at the first null byte.
(&self, store: &Store, offset: usize, max_len: usize)
| 297 | |
| 298 | /// Reads a C-style string from memory, stopping at the first null byte. |
| 299 | pub fn read_cstring_until_null(&self, store: &Store, offset: usize, max_len: usize) -> Result<CString> { |
| 300 | let bytes = self.read_vec(store, offset, max_len)?; |
| 301 | let Some(null) = bytes.iter().position(|byte| *byte == 0) else { |
| 302 | return Err(crate::Error::Other("Invalid C-style string: missing null terminator".to_string())); |
| 303 | }; |
| 304 | |
| 305 | CString::from_vec_with_nul(bytes[..=null].to_vec()) |
| 306 | .map_err(|e| crate::Error::Other(format!("Invalid C-style string: {e}"))) |
| 307 | } |
| 308 | |
| 309 | /// Reads a UTF-8 string from memory. |
| 310 | pub fn read_string(&self, store: &Store, offset: usize, len: usize) -> Result<String> { |
no test coverage detected