bug-diffutils
[Top][All Lists]
Advanced

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

[bug-diffutils] [PATCH 09/19] maint: add an assertion to suppress clang-


From: Jim Meyering
Subject: [bug-diffutils] [PATCH 09/19] maint: add an assertion to suppress clang-detected warning
Date: Fri, 20 Nov 2009 10:12:18 +0100

From: Jim Meyering <address@hidden>

The clang static analyzer reported that a NULL parent could be
dereferenced.  However, that cannot happen, because for all callers,
the parameter, parent, is always non-NULL at that point.
* src/diff.c: Include <assert.h>.
Assert that parent is not NULL.
---
 src/diff.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/diff.c b/src/diff.c
index 708d892..5e82381 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -20,6 +20,7 @@

 #define GDIFF_MAIN
 #include "diff.h"
+#include <assert.h>
 #include "paths.h"
 #include <c-stack.h>
 #include <dirname.h>
@@ -1221,8 +1222,11 @@ compare_files (struct comparison const *parent,
            status = diff_dirs (&cmp, compare_files);
          else
            {
-             char const *dir
-               = parent->file[cmp.file[0].desc == NONEXISTENT].name;
+             char const *dir;
+
+             /* PARENT must be non-NULL here.  */
+             assert (parent);
+             dir = parent->file[cmp.file[0].desc == NONEXISTENT].name;

              /* See POSIX 1003.1-2001 for this format.  */
              message ("Only in %s: %s\n", dir, name0);
-- 
1.6.5.3.433.g11067





reply via email to

[Prev in Thread] Current Thread [Next in Thread]