summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2014-01-28 13:15:19 +0100
committerMurray Cumming <murrayc@murrayc.com>2014-01-28 13:15:19 +0100
commit798a292d2ec0c05e6ccf9108c6a973651a3ddcfe (patch)
tree49109a07ce35b07200eb2604306e1afa3c2141a4
parentbdceb94b5c626a70345d9349483f3d65be0174c5 (diff)
Avoid dereferencing empty std::vector<>s.
* cairomm/context.cc: Check with empty() before using [0] on a vector. Apparently gcc allows this, but MSVC (probably correctly) does not. This fixes a crash on MS Windows. Bug #36020 (Robert Kurjata)
-rw-r--r--cairomm/context.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/cairomm/context.cc b/cairomm/context.cc
index c5d10ed..95d33e2 100644
--- a/cairomm/context.cc
+++ b/cairomm/context.cc
@@ -169,7 +169,9 @@ void Context::set_dash(std::valarray<double>& dashes, double offset)
void Context::set_dash(std::vector<double>& dashes, double offset)
{
- cairo_set_dash(cobj(), &dashes[0], dashes.size(), offset);
+ cairo_set_dash(cobj(),
+ (dashes.empty() ? 0 : &dashes[0]),
+ dashes.size(), offset);
check_object_status_and_throw_exception(*this);
}
@@ -184,7 +186,9 @@ void Context::set_dash(const std::valarray<double>& dashes, double offset)
void Context::set_dash(const std::vector<double>& dashes, double offset)
{
- cairo_set_dash(cobj(), &dashes[0], dashes.size(), offset);
+ cairo_set_dash(cobj(),
+ (dashes.empty() ? 0 : &dashes[0]),
+ dashes.size(), offset);
check_object_status_and_throw_exception(*this);
}
@@ -590,15 +594,19 @@ void Context::show_text_glyphs(const std::string& utf8,
TextClusterFlags cluster_flags)
{
cairo_show_text_glyphs(cobj(), utf8.c_str(), utf8.size(),
- &glyphs[0], glyphs.size(),
- &clusters[0], clusters.size(),
+ (glyphs.empty() ? 0 : &glyphs[0]),
+ glyphs.size(),
+ (clusters.empty() ? 0 : &clusters[0]),
+ clusters.size(),
static_cast<cairo_text_cluster_flags_t>(cluster_flags));
check_object_status_and_throw_exception(*this);
}
void Context::show_glyphs(const std::vector<Glyph>& glyphs)
{
- cairo_show_glyphs(cobj(), const_cast<cairo_glyph_t*>(&glyphs[0]), glyphs.size());
+ cairo_show_glyphs(cobj(),
+ const_cast<cairo_glyph_t*>((glyphs.empty() ? 0 : &glyphs[0])),
+ glyphs.size());
check_object_status_and_throw_exception(*this);
}
@@ -637,7 +645,7 @@ void Context::get_text_extents(const std::string& utf8, TextExtents& extents) co
void Context::get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const
{
cairo_glyph_extents(const_cast<cobject*>(cobj()),
- const_cast<cairo_glyph_t*>(&glyphs[0]),
+ const_cast<cairo_glyph_t*>(glyphs.empty() ? 0 : &glyphs[0]),
glyphs.size(), &extents);
check_object_status_and_throw_exception(*this);
}
@@ -650,7 +658,9 @@ void Context::text_path(const std::string& utf8)
void Context::glyph_path(const std::vector<Glyph>& glyphs)
{
- cairo_glyph_path(cobj(), const_cast<cairo_glyph_t*>(&glyphs[0]), glyphs.size());
+ cairo_glyph_path(cobj(),
+ const_cast<cairo_glyph_t*>(glyphs.empty() ? 0 : &glyphs[0]),
+ glyphs.size());
check_object_status_and_throw_exception(*this);
}