[librsvg/alatiera/is-a-stream: 6/9] PathBuilder::to_cairo() - Check the cr.status after completing the path
- From: Jordan Petridis <jpetridis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/alatiera/is-a-stream: 6/9] PathBuilder::to_cairo() - Check the cr.status after completing the path
- Date: Sun, 31 Mar 2019 18:57:50 +0000 (UTC)
commit 53cfaa2272d98616a22403d59b98f193e4216165
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Mar 14 13:42:44 2019 -0600
PathBuilder::to_cairo() - Check the cr.status after completing the path
Any of the individual path commands may cause the cr to enter an
error state, for example, if they come with coordinates outside of Cairo's supported range.
The *next* call to the cr will probably be something that actually
checks the status (i.e. in cairo-rs), and we don't want to panic
there.
(In the worst case, Cairo will throw out-of-memory with a super-long
path, but this is the correct place to catch that.)
rsvg_internals/src/path_builder.rs | 18 +++++++++++++++++-
rsvg_internals/src/shapes.rs | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/path_builder.rs b/rsvg_internals/src/path_builder.rs
index 077f3e8f..db133bfc 100644
--- a/rsvg_internals/src/path_builder.rs
+++ b/rsvg_internals/src/path_builder.rs
@@ -355,10 +355,26 @@ impl PathBuilder {
&self.path_commands
}
- pub fn to_cairo(&self, cr: &cairo::Context) {
+ pub fn to_cairo(&self, cr: &cairo::Context) -> Result<(), cairo::Status> {
for s in &self.path_commands {
s.to_cairo(cr);
}
+
+ // We check the cr's status right after feeding it a new path for a few reasons:
+ //
+ // * Any of the individual path commands may cause the cr to enter an error state,
+ // for example, if they come with coordinates outside of Cairo's supported range.
+ //
+ // * The *next* call to the cr will probably be something that actually checks
+ // the status (i.e. in cairo-rs), and we don't want to panic there.
+
+ let status = cr.status();
+
+ if status == cairo::Status::Success {
+ Ok(())
+ } else {
+ Err(status)
+ }
}
}
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 5b323b03..d7cbfda0 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -28,7 +28,7 @@ fn render_path_builder(
let cr = dc.get_cairo_context();
dc.set_affine_on_cr(&cr);
- builder.to_cairo(&cr);
+ builder.to_cairo(&cr)?;
if clipping {
cr.set_fill_rule(cairo::FillRule::from(values.clip_rule));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]