Skip to content

Commit d4d2b34

Browse files
author
Yorhel
committed
Entry::symlink(): Return Option<&str>
libarchive may return NULL.
1 parent 383f5fa commit d4d2b34

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/archive.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,16 @@ pub trait Entry {
161161
unsafe { ffi::archive_entry_size(self.entry()) }
162162
}
163163

164-
fn symlink(&self) -> &str {
165-
let c_str: &CStr = unsafe { CStr::from_ptr(ffi::archive_entry_symlink(self.entry())) };
164+
fn symlink(&self) -> Option<&str> {
165+
let c_str: &CStr = unsafe {
166+
let ptr = ffi::archive_entry_symlink(self.entry());
167+
if ptr.is_null() {
168+
return None;
169+
}
170+
CStr::from_ptr(ptr)
171+
};
166172
let buf: &[u8] = c_str.to_bytes();
167-
str::from_utf8(buf).unwrap()
173+
Some(str::from_utf8(buf).unwrap())
168174
}
169175

170176
fn set_filetype(&mut self, file_type: FileType) {

0 commit comments

Comments
 (0)