[gtk/fontchooser-tweaks: 2/4] fontchooserwidget: Avoid a crash




commit e12ef76de532d4cf652fe50383bc5bb378866295
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 31 09:49:40 2021 -0500

    fontchooserwidget: Avoid a crash
    
    languages may be NULL, we need to be more careful here.

 gtk/gtkfontchooserwidget.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index e16de437c4..27608eb16f 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -603,19 +603,20 @@ maybe_update_preview_text (GtkFontChooserWidget *self,
   /* Otherwise, we make a list of representative languages */
   langs = g_hash_table_new (NULL, NULL);
 
-  for (i = 0; languages[i]; i++)
-    {
-      const PangoScript *scripts;
-      int num, j;
+  if (languages)
+    for (i = 0; languages[i]; i++)
+      {
+        const PangoScript *scripts;
+        int num, j;
 
-      scripts = pango_language_get_scripts (languages[i], &num);
-      for (j = 0; j < num; j++)
-        {
-          lang = pango_script_get_sample_language (scripts[j]);
-          if (lang)
-            g_hash_table_add (langs, lang);
-        }
-    }
+        scripts = pango_language_get_scripts (languages[i], &num);
+        for (j = 0; j < num; j++)
+          {
+            lang = pango_script_get_sample_language (scripts[j]);
+            if (lang)
+              g_hash_table_add (langs, lang);
+          }
+      }
 
   /* ... and compare it to the users default and preferred languages */
   if (g_hash_table_contains (langs, default_lang) ||


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]