summaryrefslogtreecommitdiffstats
path: root/src/gradient-chemistry.cpp
diff options
context:
space:
mode:
authorKris De Gussem <kris.degussem@gmail.com>2012-04-04 18:11:46 +0000
committerKris <Kris.De.Gussem@hotmail.com>2012-04-04 18:11:46 +0000
commit658f53f8f2e1352a37841ac3287e50e44856da7d (patch)
treeea8ad03bed64c3222503ff1880fb1e4241e0e269 /src/gradient-chemistry.cpp
parentFix for 170378 : Select same objects by fill or stroke : Added stroke style (diff)
downloadinkscape-658f53f8f2e1352a37841ac3287e50e44856da7d.tar.gz
inkscape-658f53f8f2e1352a37841ac3287e50e44856da7d.zip
gradient chemistry: fix null pointer dereference
(bzr r11147)
Diffstat (limited to 'src/gradient-chemistry.cpp')
-rw-r--r--src/gradient-chemistry.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index b56352c19..a0da1e430 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -513,13 +513,16 @@ SPStop *sp_last_stop(SPGradient *gradient)
SPStop *sp_get_stop_i(SPGradient *gradient, guint stop_i)
{
SPStop *stop = gradient->getFirstStop();
+ if (!stop) {
+ return NULL;
+ }
// if this is valid but weird gradient without an offset-zero stop element,
// inkscape has created a handle for the start of gradient anyway,
// so when it asks for stop N that corresponds to stop element N-1
if (stop->offset != 0)
{
- stop_i --;
+ stop_i--;
}
for (guint i = 0; i < stop_i; i++) {
@@ -534,10 +537,10 @@ SPStop *sp_get_stop_i(SPGradient *gradient, guint stop_i)
guint32 average_color(guint32 c1, guint32 c2, gdouble p)
{
- guint32 r = (guint32) (SP_RGBA32_R_U (c1) * (1 - p) + SP_RGBA32_R_U (c2) * p);
- guint32 g = (guint32) (SP_RGBA32_G_U (c1) * (1 - p) + SP_RGBA32_G_U (c2) * p);
- guint32 b = (guint32) (SP_RGBA32_B_U (c1) * (1 - p) + SP_RGBA32_B_U (c2) * p);
- guint32 a = (guint32) (SP_RGBA32_A_U (c1) * (1 - p) + SP_RGBA32_A_U (c2) * p);
+ guint32 r = static_cast<guint32>(SP_RGBA32_R_U (c1) * (1 - p) + SP_RGBA32_R_U (c2) * p);
+ guint32 g = static_cast<guint32>(SP_RGBA32_G_U (c1) * (1 - p) + SP_RGBA32_G_U (c2) * p);
+ guint32 b = static_cast<guint32>(SP_RGBA32_B_U (c1) * (1 - p) + SP_RGBA32_B_U (c2) * p);
+ guint32 a = static_cast<guint32>(SP_RGBA32_A_U (c1) * (1 - p) + SP_RGBA32_A_U (c2) * p);
return SP_RGBA32_U_COMPOSE(r, g, b, a);
}