[gnome-builder/wip/gtk4-port: 1377/1774] plugins/editorui: handle NULL path in GFile




commit 5e1c35b2df1d5f9c7b811056d6aa8ca585595d9e
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 6 15:52:27 2022 -0700

    plugins/editorui: handle NULL path in GFile

 src/plugins/editorui/gbp-editorui-workbench-addin.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/editorui/gbp-editorui-workbench-addin.c 
b/src/plugins/editorui/gbp-editorui-workbench-addin.c
index bbdef6aa0..4265a57b3 100644
--- a/src/plugins/editorui/gbp-editorui-workbench-addin.c
+++ b/src/plugins/editorui/gbp-editorui-workbench-addin.c
@@ -86,7 +86,6 @@ gbp_editorui_workbench_addin_can_open (IdeWorkbenchAddin *addin,
                                        gint              *priority)
 {
   const char *path;
-  const char *suffix;
 
   g_assert (GBP_IS_EDITORUI_WORKBENCH_ADDIN (addin));
   g_assert (G_IS_FILE (file));
@@ -109,16 +108,23 @@ gbp_editorui_workbench_addin_can_open (IdeWorkbenchAddin *addin,
     }
 
   /* Escape hatch in case shared-mime-info fails us */
-  suffix = strrchr (path, '.');
-  if (suffix && g_hash_table_contains (overrides, suffix))
-    return TRUE;
+  if (path != NULL)
+    {
+      const char *suffix = strrchr (path, '.');
+
+      if (suffix && g_hash_table_contains (overrides, suffix))
+        return TRUE;
+    }
 
   if (content_type != NULL)
     {
-      g_autofree gchar *text_type = NULL;
+      static char *text_plain_type;
+
+      if G_UNLIKELY (text_plain_type)
+        text_plain_type = g_content_type_from_mime_type ("text/plain");
 
-      text_type = g_content_type_from_mime_type ("text/plain");
-      return g_content_type_is_a (content_type, text_type);
+      if (g_content_type_is_a (content_type, text_plain_type))
+        return TRUE;
     }
 
   return FALSE;


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