Skip to content

Commit

Permalink
rust: return empty slice without using from_raw_parts
Browse files Browse the repository at this point in the history
As this triggers rustc 1.78
unsafe precondition(s) violated: slice::from_raw_parts requires
the pointer to be aligned and non-null,
and the total size of the slice not to exceed `isize::MAX`
  • Loading branch information
catenacyber committed May 7, 2024
1 parent fbfee2b commit ce982b1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ impl StreamSlice {
self.input_len
}
pub fn as_slice(&self) -> &[u8] {
if self.input.is_null() && self.input_len == 0 {
return &[];
}
unsafe { std::slice::from_raw_parts(self.input, self.input_len as usize) }
}
pub fn is_empty(&self) -> bool {
Expand Down

0 comments on commit ce982b1

Please sign in to comment.