Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/unicode_string/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ impl<'a> NtUnicodeStr<'a> {

/// Returns a slice to the raw [`u16`] codepoints of the string.
pub fn as_slice(&self) -> &'a [u16] {
unsafe { slice::from_raw_parts(self.raw.buffer, self.len_in_elements()) }
if self.raw.buffer.is_null() {
&[]
} else {
unsafe { slice::from_raw_parts(self.raw.buffer, self.len_in_elements()) }
}
}

/// Returns a [`U16Str`] reference for this string.
Expand Down
7 changes: 6 additions & 1 deletion src/unicode_string/strmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ impl<'a> NtUnicodeStrMut<'a> {

/// Returns a mutable slice to the raw `u16` codepoints of the string.
pub fn as_mut_slice(&mut self) -> &'a mut [u16] {
unsafe { slice::from_raw_parts_mut(self.raw.buffer, self.len_in_elements()) }
if self.raw.buffer.is_null() {
&mut []
}
else {
unsafe { slice::from_raw_parts_mut(self.raw.buffer, self.len_in_elements()) }
}
}

/// Returns a mutable [`U16Str`] reference for this string.
Expand Down