Skip to content

Commit 778ad3d

Browse files
itsjunetimevinxv
authored andcommitted
Add errptr for fz_highlight_selection to catch potential throws (messense#114)
1 parent 0b1ffb5 commit 778ad3d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

mupdf-sys/wrapper.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,3 +3205,17 @@ fz_bitmap *mupdf_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pixmap, mupd
32053205
}
32063206
return bitmap;
32073207
}
3208+
3209+
int32_t mupdf_highlight_selection(fz_context *ctx, fz_stext_page *page, fz_point a, fz_point b, fz_quad *quads, int max_quads, mupdf_error_t **errptr)
3210+
{
3211+
int count = 0;
3212+
fz_try(ctx)
3213+
{
3214+
count = fz_highlight_selection(ctx, page, a, b, quads, max_quads);
3215+
}
3216+
fz_catch(ctx)
3217+
{
3218+
mupdf_save_error(ctx, errptr);
3219+
}
3220+
return count;
3221+
}

src/text_page.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ impl TextPage {
7979
let (ptr, len): (*const fz_quad, _) = rust_slice_to_ffi_ptr(quads)?;
8080

8181
Ok(unsafe {
82-
fz_highlight_selection(
82+
ffi_try!(mupdf_highlight_selection(
8383
context(),
8484
self.inner,
8585
a.into(),
8686
b.into(),
87-
ptr as *mut _,
88-
len,
89-
)
87+
ptr as *mut fz_quad,
88+
len
89+
))
9090
})
9191
}
9292
}

0 commit comments

Comments
 (0)