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
This commit is contained in:
Mikael Magnusson 2013-06-15 21:28:22 +02:00
parent 4852e59ec1
commit 1947d8def8
5 changed files with 24 additions and 4 deletions

View file

@ -88,8 +88,8 @@ gimp_colorize_config_class_init (GimpColorizeConfigClass *klass)
-1.0, 1.0, 0.0, 0); -1.0, 1.0, 0.0, 0);
gimp_hsl_set (&hsl, 0.5, 0.5, 0.5); gimp_hsl_set (&hsl, 0.5, 0.5, 0.5);
gimp_hsl_set_alpha (&hsl, 1.0);
gimp_hsl_to_rgb (&hsl, &rgb); gimp_hsl_to_rgb (&hsl, &rgb);
gimp_rgb_set_alpha (&rgb, 1.0);
g_object_class_install_property (object_class, PROP_COLOR, g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_rgb ("color", gimp_param_spec_rgb ("color",
@ -135,8 +135,8 @@ gimp_colorize_config_get_property (GObject *object,
self->hue, self->hue,
self->saturation, self->saturation,
(self->lightness + 1.0) / 2.0); (self->lightness + 1.0) / 2.0);
gimp_hsl_set_alpha (&hsl, 1.0);
gimp_hsl_to_rgb (&hsl, &rgb); gimp_hsl_to_rgb (&hsl, &rgb);
gimp_rgb_set_alpha (&rgb, 1.0);
gimp_value_set_rgb (value, &rgb); gimp_value_set_rgb (value, &rgb);
} }
break; break;

View file

@ -98,6 +98,7 @@ gimp_operation_colorize_process (GeglOperation *operation,
hsl.h = config->hue; hsl.h = config->hue;
hsl.s = config->saturation; hsl.s = config->saturation;
hsl.a = src[ALPHA];
while (samples--) while (samples--)
{ {
@ -129,7 +130,7 @@ gimp_operation_colorize_process (GeglOperation *operation,
dest[RED] = rgb.r; /* * lum; */ dest[RED] = rgb.r; /* * lum; */
dest[GREEN] = rgb.g; /* * lum; */ dest[GREEN] = rgb.g; /* * lum; */
dest[BLUE] = rgb.b; /* * lum */; dest[BLUE] = rgb.b; /* * lum */;
dest[ALPHA] = src[ALPHA]; dest[ALPHA] = rgb.a;
src += 4; src += 4;
dest += 4; dest += 4;

View file

@ -162,6 +162,7 @@ gimp_operation_hue_saturation_process (GeglOperation *operation,
rgb.r = src[RED]; rgb.r = src[RED];
rgb.g = src[GREEN]; rgb.g = src[GREEN];
rgb.b = src[BLUE]; rgb.b = src[BLUE];
rgb.a = src[ALPHA];
gimp_rgb_to_hsl (&rgb, &hsl); gimp_rgb_to_hsl (&rgb, &hsl);
@ -253,7 +254,7 @@ gimp_operation_hue_saturation_process (GeglOperation *operation,
dest[RED] = rgb.r; dest[RED] = rgb.r;
dest[GREEN] = rgb.g; dest[GREEN] = rgb.g;
dest[BLUE] = rgb.b; dest[BLUE] = rgb.b;
dest[ALPHA] = src[ALPHA]; dest[ALPHA] = rgb.a;
src += 4; src += 4;
dest += 4; dest += 4;

View file

@ -75,3 +75,19 @@ gimp_hsl_set (GimpHSL *hsl,
hsl->s = s; hsl->s = s;
hsl->l = l; 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;
}

View file

@ -40,6 +40,8 @@ void gimp_hsl_set (GimpHSL *hsl,
gdouble h, gdouble h,
gdouble s, gdouble s,
gdouble l); gdouble l);
void gimp_hsl_set_alpha (GimpHSL *hsl,
gdouble a);
G_END_DECLS G_END_DECLS