[librsvg/librsvg-2.44] PathBuilder::to_cairo() - Check the cr.status after completing the path
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.44] PathBuilder::to_cairo() - Check the cr.status after completing the path
- Date: Thu, 14 Mar 2019 21:00:28 +0000 (UTC)
commit de961d2f5e8d5ac663a0bc1f8839299216b1a9b3
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 35a19c3d..2de523dd 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 94763542..cc19d69b 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -27,7 +27,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]