[gimp] app: avoid reading uninitialized memory
- From: Mikael Magnusson <mikachu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: avoid reading uninitialized memory
- Date: Sat, 15 Jun 2013 20:44:11 +0000 (UTC)
commit 1947d8def846f30f1f488fecf51898f1a37b66ef
Author: Mikael Magnusson <mikachu src gnome org>
Date: Sat Jun 15 21:28:22 2013 +0200
app: avoid reading uninitialized memory
gimp_rgb_to_hsl and hsl_to_rgb reads the a member, so set it before
calling them. Add gimp_hsl_set_alpha() for this purpose.
Found by coverity
app/operations/gimpcolorizeconfig.c | 4 ++--
app/operations/gimpoperationcolorize.c | 3 ++-
app/operations/gimpoperationhuesaturation.c | 3 ++-
libgimpcolor/gimphsl.c | 16 ++++++++++++++++
libgimpcolor/gimphsl.h | 2 ++
5 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/app/operations/gimpcolorizeconfig.c b/app/operations/gimpcolorizeconfig.c
index 02975d6..a276e59 100644
--- a/app/operations/gimpcolorizeconfig.c
+++ b/app/operations/gimpcolorizeconfig.c
@@ -88,8 +88,8 @@ gimp_colorize_config_class_init (GimpColorizeConfigClass *klass)
-1.0, 1.0, 0.0, 0);
gimp_hsl_set (&hsl, 0.5, 0.5, 0.5);
+ gimp_hsl_set_alpha (&hsl, 1.0);
gimp_hsl_to_rgb (&hsl, &rgb);
- gimp_rgb_set_alpha (&rgb, 1.0);
g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_rgb ("color",
@@ -135,8 +135,8 @@ gimp_colorize_config_get_property (GObject *object,
self->hue,
self->saturation,
(self->lightness + 1.0) / 2.0);
+ gimp_hsl_set_alpha (&hsl, 1.0);
gimp_hsl_to_rgb (&hsl, &rgb);
- gimp_rgb_set_alpha (&rgb, 1.0);
gimp_value_set_rgb (value, &rgb);
}
break;
diff --git a/app/operations/gimpoperationcolorize.c b/app/operations/gimpoperationcolorize.c
index 38c86c5..1db74fb 100644
--- a/app/operations/gimpoperationcolorize.c
+++ b/app/operations/gimpoperationcolorize.c
@@ -98,6 +98,7 @@ gimp_operation_colorize_process (GeglOperation *operation,
hsl.h = config->hue;
hsl.s = config->saturation;
+ hsl.a = src[ALPHA];
while (samples--)
{
@@ -129,7 +130,7 @@ gimp_operation_colorize_process (GeglOperation *operation,
dest[RED] = rgb.r; /* * lum; */
dest[GREEN] = rgb.g; /* * lum; */
dest[BLUE] = rgb.b; /* * lum */;
- dest[ALPHA] = src[ALPHA];
+ dest[ALPHA] = rgb.a;
src += 4;
dest += 4;
diff --git a/app/operations/gimpoperationhuesaturation.c b/app/operations/gimpoperationhuesaturation.c
index c812787..36fa5c5 100644
--- a/app/operations/gimpoperationhuesaturation.c
+++ b/app/operations/gimpoperationhuesaturation.c
@@ -162,6 +162,7 @@ gimp_operation_hue_saturation_process (GeglOperation *operation,
rgb.r = src[RED];
rgb.g = src[GREEN];
rgb.b = src[BLUE];
+ rgb.a = src[ALPHA];
gimp_rgb_to_hsl (&rgb, &hsl);
@@ -253,7 +254,7 @@ gimp_operation_hue_saturation_process (GeglOperation *operation,
dest[RED] = rgb.r;
dest[GREEN] = rgb.g;
dest[BLUE] = rgb.b;
- dest[ALPHA] = src[ALPHA];
+ dest[ALPHA] = rgb.a;
src += 4;
dest += 4;
diff --git a/libgimpcolor/gimphsl.c b/libgimpcolor/gimphsl.c
index 9c76778..6f5722b 100644
--- a/libgimpcolor/gimphsl.c
+++ b/libgimpcolor/gimphsl.c
@@ -75,3 +75,19 @@ gimp_hsl_set (GimpHSL *hsl,
hsl->s = s;
hsl->l = l;
}
+
+/**
+ * gimp_hsl_set_alpha:
+ * @hsl:
+ * @a:
+ *
+ * Since: GIMP 2.10
+ **/
+void
+gimp_hsl_set_alpha (GimpHSL *hsl,
+ gdouble a)
+{
+ g_return_if_fail (hsl != NULL);
+
+ hsl->a = a;
+}
diff --git a/libgimpcolor/gimphsl.h b/libgimpcolor/gimphsl.h
index 81d2e46..af76f7f 100644
--- a/libgimpcolor/gimphsl.h
+++ b/libgimpcolor/gimphsl.h
@@ -40,6 +40,8 @@ void gimp_hsl_set (GimpHSL *hsl,
gdouble h,
gdouble s,
gdouble l);
+void gimp_hsl_set_alpha (GimpHSL *hsl,
+ gdouble a);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]