[Bug c/71701] New: bogus token in -Wmaybe-uninitialized warning

palves at redhat dot com gcc-bugzilla@gcc.gnu.org
Wed Jun 29 15:46:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71701

            Bug ID: 71701
           Summary: bogus token in -Wmaybe-uninitialized warning
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: palves at redhat dot com
  Target Milestone: ---

This testcase makes gcc issue a confusing warning:

$ cat strtok.c 
char *xstrdup (const char *) __attribute__ ((__returns_nonnull__));

#define PREFIX "some "

#include <string.h>

int
main ()
{
  char *saveptr;
  char *name = xstrdup (PREFIX "name");
  char *tail = name + sizeof (PREFIX) - 1;
  char *token = strtok_r (tail, " ", &saveptr);

  return token [0];
}
$ /opt/gcc/bin/gcc -O2 strtok.c -c -Wall  
strtok.c: In function ‘main’:
strtok.c:15:16: warning: ‘__s’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   return token [0];
          ~~~~~~^~~
$

It's confusing because nowhere in the sources there's "__s" variable.

"__s" here is actually the parameter of an inlined function,
in /usr/include/bits2.h:

__STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp);
__STRING_INLINE char *
__strtok_r_1c (char *__s, char __sep, char **__nextp)
{
  char *__result;
  if (__s == NULL)
    __s = *__nextp;
...


More information about the Gcc-bugs mailing list