libgimpconfig: don't crash if g_value_get_boxed() returns NULL

This commit is contained in:
Michael Natterer
2010-09-25 16:02:02 +02:00
parent 62f8f559a7
commit 6b30250353

View File

@ -427,11 +427,14 @@ gimp_config_serialize_value (const GValue *value,
if (GIMP_VALUE_HOLDS_MATRIX2 (value)) if (GIMP_VALUE_HOLDS_MATRIX2 (value))
{ {
GimpMatrix2 *trafo; GimpMatrix2 *trafo;
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
gint i, j, k;
trafo = g_value_get_boxed (value); trafo = g_value_get_boxed (value);
if (trafo)
{
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
gint i, j, k;
for (i = 0, k = 0; i < 2; i++) for (i = 0, k = 0; i < 2; i++)
for (j = 0; j < 2; j++, k++) for (j = 0; j < 2; j++, k++)
g_ascii_formatd (buf[k], g_ascii_formatd (buf[k],
@ -439,6 +442,12 @@ gimp_config_serialize_value (const GValue *value,
g_string_append_printf (str, "(matrix %s %s %s %s)", g_string_append_printf (str, "(matrix %s %s %s %s)",
buf[0], buf[1], buf[2], buf[3]); buf[0], buf[1], buf[2], buf[3]);
}
else
{
g_string_append (str, "(matrix 1.0 1.0 1.0 1.0)");
}
return TRUE; return TRUE;
} }
@ -494,10 +503,13 @@ gimp_config_serialize_rgb (const GValue *value,
gboolean has_alpha) gboolean has_alpha)
{ {
GimpRGB *rgb; GimpRGB *rgb;
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
rgb = g_value_get_boxed (value); rgb = g_value_get_boxed (value);
if (rgb)
{
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->r); g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->r);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->g); g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->g);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->b); g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->b);
@ -517,3 +529,6 @@ gimp_config_serialize_rgb (const GValue *value,
return TRUE; return TRUE;
} }
return FALSE;
}