Skip to content

Commit

Permalink
Handle null bitmap pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominaezzz committed Apr 28, 2022
1 parent 67e31e0 commit 069ada9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ impl Bitmap {
/// A typeless pointer to the bitmap buffer. This value should be aligned
/// on 32-bit boundaries in most cases.
pub fn buffer(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
(*self.raw).buffer,
(self.pitch().abs() * self.rows()) as usize
)
let buffer_size = (self.pitch().abs() * self.rows()) as usize;
if buffer_size > 0 {
unsafe {
slice::from_raw_parts((*self.raw).buffer, buffer_size)
}
} else {
// When buffer_size is 0, the buffer pointer will be null.
&[]
}
}

Expand Down

0 comments on commit 069ada9

Please sign in to comment.