This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

nonnull, -Wnonnull, and do/while


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]