Skip to content

Commit

Permalink
fix: account for null edid pointer
Browse files Browse the repository at this point in the history
Co-authored-by: Lysander Mealy <[email protected]>
  • Loading branch information
jasondyoungberg and lylythechosenone authored Jun 8, 2024
1 parent b581cbd commit 391ed0f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/framebuffer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Auxiliary types for the [framebuffer request](crate::request::FramebufferRequest)
use core::ffi::c_void;
use core::{ffi::c_void, ptr::NonNull};

#[derive(Clone, Copy)]
#[repr(C)]
Expand All @@ -19,7 +19,7 @@ pub(crate) struct RawFramebufferV0 {
blue_mask_shift: u8,
_unused: [u8; 7],
edid_size: u64,
edid: *mut u8,
edid: Option<NonNull<u8>>,
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -164,8 +164,12 @@ impl<'a> Framebuffer<'a> {
}

/// The raw EDID bytes of the display attached to this framebuffer.
pub fn edid(&self) -> &[u8] {
unsafe { core::slice::from_raw_parts(self.inner.v0.edid, self.inner.v0.edid_size as usize) }
pub fn edid(&self) -> Option<&[u8]> {
unsafe {
self.inner.v0.edid.map(|ptr| {
core::slice::from_raw_parts(ptr.as_ptr(), self.inner.v0.edid_size as usize)
})
}
}

/// The video modes supported on this framebuffer. Only available on
Expand Down

0 comments on commit 391ed0f

Please sign in to comment.