[gnome-builder/gnome-builder-3-32] sourceview: check for NULL on various path filters



commit 325cfb6d9e403bf52a229308e8479505ab7f6d66
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jan 14 11:49:27 2020 -0800

    sourceview: check for NULL on various path filters
    
    Fixes #577

 src/libide/sourceview/ide-snippet-context.c | 35 +++++++++++++++--------------
 1 file changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/src/libide/sourceview/ide-snippet-context.c b/src/libide/sourceview/ide-snippet-context.c
index 9e7a3fc8b..c58603186 100644
--- a/src/libide/sourceview/ide-snippet-context.c
+++ b/src/libide/sourceview/ide-snippet-context.c
@@ -413,17 +413,16 @@ filter_space (const gchar *input)
 static gchar *
 filter_descend_path (const gchar *input)
 {
-   const char* pos = strchr (input, G_DIR_SEPARATOR);
-   if (pos == input)
-     {
-       input++;
-       pos = strchr (input, G_DIR_SEPARATOR);
-     }
-   if (pos)
-     {
-       pos++;
-       return g_strdup (pos);
-     }
+  const gchar *pos;
+
+  if (input == NULL)
+    return NULL;
+
+  while (*input == G_DIR_SEPARATOR)
+    input++;
+
+  if ((pos = strchr (input, G_DIR_SEPARATOR)))
+    return g_strdup (pos + 1);
 
    return NULL;
 }
@@ -445,19 +444,22 @@ filter_stripsuffix (const gchar *input)
 static gchar *
 filter_slash_to_dots (const gchar *input)
 {
-  gunichar c;
   GString *str;
+  gunichar ch;
+
+  if (input == NULL)
+    return NULL;
 
   str = g_string_new (NULL);
 
   for (; *input; input = g_utf8_next_char (input))
     {
-      c = g_utf8_get_char (input);
+      ch = g_utf8_get_char (input);
 
-      if (c == G_DIR_SEPARATOR)
+      if (ch == G_DIR_SEPARATOR)
         g_string_append_c (str, '.');
       else
-        g_string_append_c (str, c);
+        g_string_append_unichar (str, ch);
     }
 
   return g_string_free (str, FALSE);
@@ -470,8 +472,7 @@ apply_filter (gchar       *input,
   InputFilter filter_func;
   gchar *tmp;
 
-  filter_func = g_hash_table_lookup (filters, filter);
-  if (filter_func)
+  if ((filter_func = g_hash_table_lookup (filters, filter)))
     {
       tmp = input;
       input = filter_func (input);


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