[Bug middle-end/78998] New: missing -Wnonnull for an unconditional call to strlen with a null argument

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 5 03:24:00 GMT 2017


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

            Bug ID: 78998
           Summary: missing -Wnonnull for an unconditional call to strlen
                    with a null argument
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The newly enhanced -Wnonnull warning misses the following trivial null pointer
dereference by strlen:

$ cat b.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout b.c 
int f (int i)
{
  char *s = 0;
  switch (i) case 0: s = "";
  if (!i) s = 0;

  return __builtin_strlen (s);
}

;; Function f (f, funcdef_no=0, decl_uid=1795, cgraph_uid=0, symbol_order=0)

f (int i)
{
  long unsigned int _1;
  int _6;

  <bb 2> [100.00%]:
  _1 = __builtin_strlen (0B);
  _6 = (int) _1;
  return _6;

}


More information about the Gcc-bugs mailing list