Avoid UB if the CFData pointer is NULL (#688)
This commit is contained in:
@@ -81,7 +81,14 @@ impl CFData {
|
||||
/// read-only.
|
||||
#[inline]
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
unsafe { slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) }
|
||||
unsafe {
|
||||
let ptr = CFDataGetBytePtr(self.0);
|
||||
// Rust slice must never have a NULL pointer
|
||||
if ptr.is_null() {
|
||||
return &[];
|
||||
}
|
||||
slice::from_raw_parts(ptr, self.len() as usize)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the length of this byte buffer.
|
||||
|
||||
Reference in New Issue
Block a user