Skip to content

Commit

Permalink
Make data allocation fallible in PdfPage::pixmap
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Apr 8, 2022
1 parent f4538c6 commit 012de2a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/document/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,13 @@ impl<'a> PdfPage<'a> {
let width = (*pixmap).w as u32;
let height = (*pixmap).h as u32;
let len = (width * height) as usize;
let data = slice::from_raw_parts((*pixmap).samples, len).to_vec();
let samples = slice::from_raw_parts((*pixmap).samples, len);
let mut data = Vec::new();
if data.try_reserve(len).is_err() {
fz_drop_pixmap(self.ctx.0, pixmap);
return None;
}
data.extend(samples);

fz_drop_pixmap(self.ctx.0, pixmap);

Expand Down

0 comments on commit 012de2a

Please sign in to comment.