Benno Lossin <benno.lossin@xxxxxxxxx> writes: > On 11/29/23 14:11, Alice Ryhl wrote: >> + /// Returns the bytes for this security context. >> + pub fn as_bytes(&self) -> &[u8] { >> + let mut ptr = self.secdata; >> + if ptr.is_null() { >> + // Many C APIs will use null pointers for strings of length zero, but > > I would just write that the secctx API uses null pointers to denote a > string of length zero. I don't actually know whether it can ever be null, I just wanted to stay on the safe side. >> + // `slice::from_raw_parts` doesn't allow the pointer to be null even if the length is >> + // zero. Replace the pointer with a dangling but non-null pointer in this case. >> + debug_assert_eq!(self.seclen, 0); > > I am feeling a bit uncomfortable with this, why can't we just return > an empty slice in this case? I can do that, but to be clear, what I'm doing here is also definitely okay. Alice