Finally some good use of the GCC analyzer. gcc reports this warning:

-Wanalyzer-possible-null-argument       
../../../gettext-tools/gnulib-lib/vc-mtime.c:374:7: warning: use of 
possibly-NULL 'dir2' where non-null expected [CWE-690]

The cause is that xgetcwd() may return NULL, which I did not remember.

Fixed like this:


2025-05-04  Bruno Haible  <br...@clisp.org>

        vc-mtime: Don't crash if xgetcwd() returns NULL.
        * lib/vc-mtime.c (max_vc_mtime): Skip the git processing if xgetcwd()
        returns NULL.

diff --git -w a/lib/vc-mtime.c b/lib/vc-mtime.c
index ad529ea317..4ebc249d84 100644
--- a/lib/vc-mtime.c
+++ b/lib/vc-mtime.c
@@ -518,6 +518,8 @@ max_vc_mtime (struct timespec *max_of_mtimes,
       if (git_checkout != NULL)
         {
           char *currdir = xgetcwd ();
+          if (currdir != NULL)
+            {
               /* git_checkout is expected to be an ancestor directory of the
                  current directory.  */
               long ancestor = ancestor_level (git_checkout, currdir);
@@ -934,6 +936,7 @@ max_vc_mtime (struct timespec *max_of_mtimes,
             }
           free (git_checkout);
         }
+    }
 
   /* For the files that are not under version control, or that are modified
      compared to HEAD, use the file's time stamp.  */




Reply via email to