Skip to content

Commit

Permalink
Fix segfault in Entry::value creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Jan 25, 2021
1 parent 3f45aee commit 028f4f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a, T> Iterator for EntryList<'a, T> {
let name =
unsafe { util::ptr_to_os_str_unchecked(ffi::udev_list_entry_get_name(self.entry)) };
let value = unsafe {
util::ptr_to_os_str_unchecked(ffi::udev_list_entry_get_value(self.entry))
util::ptr_to_os_str(ffi::udev_list_entry_get_value(self.entry))
};

self.entry = unsafe { ffi::udev_list_entry_get_next(self.entry) };
Expand All @@ -43,7 +43,7 @@ impl<'a, T> Iterator for EntryList<'a, T> {
/// Rust wrapper for each entry in `List`, each of which contains a name and a value.
pub struct Entry<'a> {
pub(crate) name: &'a OsStr,
pub(crate) value: &'a OsStr,
pub(crate) value: Option<&'a OsStr>,
}

impl<'a> Entry<'a> {
Expand All @@ -54,6 +54,6 @@ impl<'a> Entry<'a> {

/// Returns the entry value.
pub fn value(&self) -> &OsStr {
self.value
self.value.unwrap_or_else(|| OsStr::new(""))
}
}

0 comments on commit 028f4f5

Please sign in to comment.