This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
nonnull, -Wnonnull, and do/while
- From: Stefan Sobernig <ss at thinkersfoot dot net>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 16 Feb 2016 10:43:08 +0100
- Subject: nonnull, -Wnonnull, and do/while
- Authentication-results: sourceware.org; auth=none
- Reply-to: stefan dot sobernig at wu dot ac dot at
Hi
We have a number of do/while loops with NULL checks in their exit
conditions:
#include <stdio.h>
static void f(const char *s) __attribute__((nonnull(1)));
int main(void)
{
const char *p = "X";
f(p);
}
static void f(const char *s)
{
do {
printf("%s\n",s);
s = NULL;
} while (s != NULL);
}
Under a recent gcc 6 [*], we run into -Wnonnull warnings using the
nonnull attribute:
test.c: In function 'f':
test.c:16:14: warning: nonnull argument 's' compared to NULL [-Wnonnull]
} while (s != NULL);
Am I missing sth.? Is this a false positive?
I'd appreciate your guidance!
Stefan
[*] gcc-mp-6 (MacPorts gcc6 6-20160207_0) 6.0.0 20160207 (experimental)