I'm not sure whether to report this to gcc or glibc - maybe it falls
in-between.

#include <string.h>
void g(char *);
void f(char *a)
{
        char *p, *q;
        while ((q = strtok_r(a, ":", &p)))
                g(q);
}

with -O1 -Wall -Wwrite-strings, gives:

warning: 'p' may be used uninitialized in this function

This comes from the inline expansion of strtok_r(), after reduction:

extern __inline char *
__strtok_r_1c (char *__s, char __sep, char **__nextp)
{
  char *__result;
  if (__s == ((void *)0))
    __s = *__nextp;
  while (*__s == __sep)
    ++__s;
  __result = ((void *)0);
  if (*__s != '\0')
    {
      __result = __s++;
      while (*__s != '\0')
 if (*__s++ == __sep)
   {
     __s[-1] = '\0';
     break;
   }
      *__nextp = __s;
    }
  return __result;
}

void g(char *);
void f(char *a)
{
        char *p, *q;
        while ((q = __strtok_r_1c (a, ':', &p)))
                g(q);
}

I don't know what glibc could do to prevent this (except dropping this
optimisation).


-- 
           Summary: spurious strtok_r warning with -Wwrite-strings
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mattias at virtutech dot se
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26634

Reply via email to