[Bug nss/32465] New: ./getaddrinfo.c:1884:11: error: variable 'endp' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]

hjl.tools at gmail dot com sourceware-bugzilla@sourceware.org
Mon Dec 16 13:26:50 GMT 2024


https://sourceware.org/bugzilla/show_bug.cgi?id=32465

            Bug ID: 32465
           Summary: ./getaddrinfo.c:1884:11: error: variable 'endp' is
                    used uninitialized whenever '||' condition is true
                    [-Werror,-Wsometimes-uninitialized]
           Product: glibc
           Version: 2.41
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nss
          Assignee: unassigned at sourceware dot org
          Reporter: hjl.tools at gmail dot com
  Target Milestone: ---

When Clang 19 was used to compiler glibc test, I got

./getaddrinfo.c:1884:11: error: variable 'endp' is used uninitialized whenever
'||' condition is true [-Werror,-Wsometimes-uninitialized]
 1884 |       && (cp == NULL
      |           ^~~~~~~~~~
./getaddrinfo.c:1887:11: note: uninitialized use occurs here
 1887 |       && *endp == '\0'
      |           ^~~~
./getaddrinfo.c:1884:11: note: remove the '||' if its condition is always false
 1884 |       && (cp == NULL
      |           ^~~~~~~~~~
 1885 |           || (bits = strtoul (cp, &endp, 10)) != ULONG_MAX
      |           ~~
./getaddrinfo.c:1875:13: note: initialize the variable 'endp' to silence this
warning
 1875 |   char *endp;
      |             ^
      |              = NULL
./getaddrinfo.c:2045:13: error: variable 'endp' is used uninitialized whenever
'||' condition is true [-Werror,-Wsometimes-uninitialized]
 2045 |                       && (cp == NULL
      |                           ^~~~~~~~~~
./getaddrinfo.c:2048:13: note: uninitialized use occurs here
 2048 |                       && *endp == '\0'
      |                           ^~~~
./getaddrinfo.c:2045:13: note: remove the '||' if its condition is always false
 2045 |                       && (cp == NULL
      |                           ^~~~~~~~~~
 2046 |                           || (bits = strtoul (cp, &endp, 10)) !=
ULONG_MAX
      |                           ~~
./getaddrinfo.c:2034:18: note: initialize the variable 'endp' to silence this
warning
 2034 |               char *endp;
      |                         ^
      |                          = NULL
2 errors generated.

The codes are

  char *endp;

  bits = 128; 
  __set_errno (0); 
  char *cp = strchr (val1, '/');
  if (cp != NULL)
    *cp++ = '\0';
  *pos = cp;
  if (inet_pton (AF_INET6, val1, &prefix)
      && (cp == NULL 
          || (bits = strtoul (cp, &endp, 10)) != ULONG_MAX
          || errno != ERANGE)
      && *endp == '\0' 
      && bits <= 128
      && ((val = strtoul (val2, &endp, 10)) != ULONG_MAX
          || errno != ERANGE)
      && *endp == '\0' 
      && val <= INT_MAX)
    {    

endp may be uninitialized when cp == NULL.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list