From 5dc8dea8695786daec491a6655f99c0791e47f5c Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Tue, 7 May 2024 10:18:14 +0200 Subject: [PATCH] rust: return empty slice without using from_raw_parts 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` Ticket: 7013 --- rust/src/applayer.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 522143fb6d..dbf4b2cd2d 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -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 { -- 2.47.2