From 3704fc6f2e6716d95446cd10aa2ec798be13472c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 4 Nov 2016 20:17:32 -0400 Subject: [PATCH] Remove NULL checks for AFS_NONNULL parameters MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Benjamin Kaduk --- src/kauth/kalocalcell.c | 2 -- src/opr/casestrcpy.c | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/kauth/kalocalcell.c b/src/kauth/kalocalcell.c index c28cb4a..7c2f499 100644 --- a/src/kauth/kalocalcell.c +++ b/src/kauth/kalocalcell.c @@ -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); diff --git a/src/opr/casestrcpy.c b/src/opr/casestrcpy.c index 37f5c4c..8cfe37d 100644 --- a/src/opr/casestrcpy.c +++ b/src/opr/casestrcpy.c @@ -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; -- 1.9.4