layout: Never return NULL from pango_layout_get_text()
authorBenjamin Otte <otte@redhat.com>
Mon, 9 Sep 2013 15:12:50 +0000 (17:12 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Sep 2013 15:12:50 +0000 (17:12 +0200)
layouts get initialized with text == NULL as an optimization (avoid a
malloc). But pango_layout_set_text (layout, NULL, 0); will set the text
to "", so it is impossible to set a NULL text.

Fxies crashers in various places that assume NULL return values never
happen.

https://bugzilla.gnome.org/show_bug.cgi?id=707659

pango/pango-layout.c

index cff9c51..2b0147f 100644 (file)
@@ -1100,6 +1100,11 @@ pango_layout_get_text (PangoLayout *layout)
 {
   g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL);
 
+  /* We don't ever want to return NULL as the text.
+   */
+  if (G_UNLIKELY (!layout->text))
+    return "";
+
   return layout->text;
 }