]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Remove NULL checks for AFS_NONNULL parameters
authorAnders Kaseorg <andersk@mit.edu>
Sat, 5 Nov 2016 00:17:32 +0000 (20:17 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Mon, 28 Nov 2016 02:54:34 +0000 (21:54 -0500)
Recent GCC warns about opr_Assert(p != NULL), where p is an
__attribute__((__nonnull__)) parameter, just like clang did before those
clang warnings were silenced by 11852, 11853.

Now, we could go and add more autoconf tests and pragmas to silence the
GCC versions of these warnings.  However, I maintain that silencing the
warnings is the wrong approach.  The asserts in question have no
purpose.  They do not add any safety, because GCC and clang are
optimizing them away at compile time (without proof!—they take the
declaration at its word that NULL will never be passed).  Just remove
them.

Fixes these warnings (errors with --enable-checking) from GCC 6.2:

In file included from casestrcpy.c:17:0:
casestrcpy.c: In function ‘opr_lcstring’:
casestrcpy.c:26:31: error: nonnull argument ‘d’ compared to NULL [-Werror=nonnull-compare]
     opr_Assert(s != NULL && d != NULL);
                               ^
/…/openafs/include/afs/opr.h:28:15: note: in definition of macro ‘__opr_Assert’
     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
               ^~
casestrcpy.c:26:5: note: in expansion of macro ‘opr_Assert’
     opr_Assert(s != NULL && d != NULL);
     ^~~~~~~~~~
casestrcpy.c:26:18: error: nonnull argument ‘s’ compared to NULL [-Werror=nonnull-compare]
     opr_Assert(s != NULL && d != NULL);
                  ^
/…/openafs/include/afs/opr.h:28:15: note: in definition of macro ‘__opr_Assert’
     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
               ^~
casestrcpy.c:26:5: note: in expansion of macro ‘opr_Assert’
     opr_Assert(s != NULL && d != NULL);
     ^~~~~~~~~~
casestrcpy.c: In function ‘opr_ucstring’:
casestrcpy.c:46:31: error: nonnull argument ‘d’ compared to NULL [-Werror=nonnull-compare]
     opr_Assert(s != NULL && d != NULL);
                               ^
/…/openafs/include/afs/opr.h:28:15: note: in definition of macro ‘__opr_Assert’
     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
               ^~
casestrcpy.c:46:5: note: in expansion of macro ‘opr_Assert’
     opr_Assert(s != NULL && d != NULL);
     ^~~~~~~~~~
casestrcpy.c:46:18: error: nonnull argument ‘s’ compared to NULL [-Werror=nonnull-compare]
     opr_Assert(s != NULL && d != NULL);
                  ^
/…/openafs/include/afs/opr.h:28:15: note: in definition of macro ‘__opr_Assert’
     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
               ^~
casestrcpy.c:46:5: note: in expansion of macro ‘opr_Assert’
     opr_Assert(s != NULL && d != NULL);
     ^~~~~~~~~~
casestrcpy.c: In function ‘opr_strcompose’:
/…/openafs/include/afs/opr.h:28:12: error: nonnull argument ‘buf’ compared to NULL [-Werror=nonnull-compare]
     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
            ^
/…/openafs/include/afs/opr.h:37:25: note: in expansion of macro ‘__opr_Assert’
 # define opr_Assert(ex) __opr_Assert(ex)
                         ^~~~~~~~~~~~
casestrcpy.c:98:5: note: in expansion of macro ‘opr_Assert’
     opr_Assert(buf != NULL);
     ^~~~~~~~~~
kalocalcell.c: In function ‘ka_CellToRealm’:
/…/openafs/include/afs/opr.h:28:12: error: nonnull argument ‘realm’ compared to NULL [-Werror=nonnull-compare]
     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
            ^
/…/openafs/include/afs/opr.h:37:25: note: in expansion of macro ‘__opr_Assert’
 # define opr_Assert(ex) __opr_Assert(ex)
                         ^~~~~~~~~~~~
kalocalcell.c:117:5: note: in expansion of macro ‘opr_Assert’
     opr_Assert(realm != NULL);
     ^~~~~~~~~~

Change-Id: I6fd618ed49255d7b3de2f8f3424d9659890829c0
Reviewed-on: https://gerrit.openafs.org/12442
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
src/kauth/kalocalcell.c
src/opr/casestrcpy.c

index c28cb4abad9ed99b2d40b962c42a73a127f05522..7c2f4994c5e93c2c40b086d3a8ddbbec6a302b5c 100644 (file)
@@ -114,8 +114,6 @@ ka_CellToRealm(char *cell, char *realm, int *local)
 {
     int code = 0;
 
-    opr_Assert(realm != NULL);
-
     LOCK_GLOBAL_MUTEX;
     code = ka_ExpandCell(cell, realm, local);
     ucstring(realm, realm, MAXKTCREALMLEN);
index 37f5c4cabc094925aae337363e24b271ad4d2722..8cfe37d99344b4a1c0278f3096d7a6ee16172f21 100644 (file)
@@ -23,7 +23,6 @@ lcstring(char *d, const char *s, int n)
     char *original_d = d;
     char c;
 
-    opr_Assert(s != NULL && d != NULL);
     while (n) {
        c = *s++;
        if (isupper(c))
@@ -43,7 +42,6 @@ ucstring(char *d, const char *s, int n)
     char *original_d = d;
     char c;
 
-    opr_Assert(s != NULL && d != NULL);
     while (n) {
        c = *s++;
        if (islower(c))
@@ -95,7 +93,6 @@ strcompose(char *buf, size_t len, ...)
     char *str;
     size_t slen;
 
-    opr_Assert(buf != NULL);
     if (len <= 0)
        return NULL;