text: Do not segfault with NULL :font-name

Make sure that we have a fall back in place for the default font name
string, and use g_strcmp0 to protect ourselves from NULL strings.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2417
This commit is contained in:
Emmanuele Bassi 2010-11-14 15:23:36 +00:00
parent 9249bd8411
commit e6bc65b5c3

View File

@ -3864,13 +3864,21 @@ clutter_text_set_font_name (ClutterText *self,
g_return_if_fail (CLUTTER_IS_TEXT (self)); g_return_if_fail (CLUTTER_IS_TEXT (self));
/* get the default font name from the backend */ /* get the default font name from the backend */
if (!font_name || font_name[0] == '\0') if (font_name == NULL || font_name[0] == '\0')
{ {
ClutterSettings *settings = clutter_settings_get_default (); ClutterSettings *settings = clutter_settings_get_default ();
gchar *default_font_name = NULL; gchar *default_font_name = NULL;
g_object_get (settings, "font-name", default_font_name, NULL); g_object_get (settings, "font-name", &default_font_name, NULL);
font_name = default_font_name;
if (default_font_name != NULL)
font_name = default_font_name;
else
{
/* last fallback */
default_font_name = g_strdup ("Sans 12");
}
is_default_font = TRUE; is_default_font = TRUE;
} }
else else
@ -3878,7 +3886,7 @@ clutter_text_set_font_name (ClutterText *self,
priv = self->priv; priv = self->priv;
if (priv->font_name && strcmp (priv->font_name, font_name) == 0) if (g_strcmp0 (priv->font_name, font_name) == 0)
goto out; goto out;
desc = pango_font_description_from_string (font_name); desc = pango_font_description_from_string (font_name);