[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-dev] What to do when a dynamic cast fail in librender?
From: |
Petter Reinholdtsen |
Subject: |
[Gnash-dev] What to do when a dynamic cast fail in librender? |
Date: |
Sun, 20 Apr 2014 08:58:01 +0200 |
User-agent: |
Mutt/1.5.20 (2009-12-10) |
Hi.
The only Coverity issue reported in librendrer is a potential null
pointer dereference. I thought I should try to bring down the number
of defects in this module to zero, but I am unable to figure out how
to fix it. The problem is in the function cairo_pattern_t*
operator()(const BitmapFill& f) const. There, the dynamic_cast might
fail, but there is no check before using the result. As far as I can
tell, there is no alternative to throwing an exception to report the
error, but as far as I can see no other part of librendrer throw any
exceptions. Is it safe to introduce throwing to report the problem?
Here is a sketch for a fix, to give you an idea about the location in
the code:
diff --git a/librender/cairo/Renderer_cairo.cpp
b/librender/cairo/Renderer_cairo.cpp
index c597dd4..2e95686 100644
--- a/librender/cairo/Renderer_cairo.cpp
+++ b/librender/cairo/Renderer_cairo.cpp
@@ -299,6 +299,9 @@ struct StyleHandler :
boost::static_visitor<cairo_pattern_t*>
const bitmap_info_cairo* binfo =
dynamic_cast<const bitmap_info_cairo*>(bm);
+ if (NULL == binfo) { // CID 1154657, binfo used below
+ throw std::bad_cast();
+ }
cairo_matrix_t mat;
init_cairo_matrix(&mat, m);
--
Happy hacking
Petter Reinholdtsen
- [Gnash-dev] What to do when a dynamic cast fail in librender?,
Petter Reinholdtsen <=