[glib] glocalfile: Assert against a potential NULL pointer dereference



commit d09c219696512d5f365e0920c106b58c0d70bd19
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Fri Jun 20 21:25:07 2014 +0100

    glocalfile: Assert against a potential NULL pointer dereference
    
    This was confusing some static analysis. Through canonicalize_filename()
    at construction time, we guaranteed that ->filename is canonical and
    absolute, so g_path_skip_root() should never fail.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731988

 gio/glocalfile.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index a5a6beb..0a1cadf 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -503,8 +503,11 @@ g_local_file_get_parent (GFile *file)
   char *dirname;
   GFile *parent;
 
-  /* Check for root */
+  /* Check for root; local->filename is guaranteed to be absolute, so
+   * g_path_skip_root() should never return NULL. */
   non_root = g_path_skip_root (local->filename);
+  g_assert (non_root != NULL);
+
   if (*non_root == 0)
     return NULL;
 


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