[glib: 1/3] glocalfile: Add an assertion to help static analysis




commit 3a7acd24a94cb6e2a212d9fab9acd4c6d44a1665
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Dec 8 11:15:25 2020 +0000

    glocalfile: Add an assertion to help static analysis
    
    Static analysis of the call to `g_dir_new_from_dirp()` is tricky,
    because the call is across library boundaries and indirected through a
    vfunc map because it’s private to libglib.
    
    Help the static analyser by adding an assertion about the input and
    output values for `g_dir_new_from_dirp()`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/glocalfile.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 15738d8b8..a35368c71 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -2842,22 +2842,24 @@ g_local_file_measure_size_of_contents (gint           fd,
   gboolean success = TRUE;
   const gchar *name;
   GDir *dir;
+  gint saved_errno;
 
 #ifdef AT_FDCWD
   {
-    /* If this fails, we want to preserve the errno from fopendir() */
+    /* If this fails, we want to preserve the errno from fdopendir() */
     DIR *dirp;
     dirp = fdopendir (fd);
+    saved_errno = errno;
     dir = dirp ? GLIB_PRIVATE_CALL(g_dir_new_from_dirp) (dirp) : NULL;
+    g_assert ((dirp == NULL) == (dir == NULL));
   }
 #else
   dir = GLIB_PRIVATE_CALL(g_dir_open_with_errno) (dir_name->data, 0);
+  saved_errno = errno;
 #endif
 
   if (dir == NULL)
     {
-      gint saved_errno = errno;
-
 #ifdef AT_FDCWD
       close (fd);
 #endif


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