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

            Bug ID: 86199
           Summary: warn on calls to strlen with same argument as in
                    strnlen
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The the call to strlen() in the test case below is most likely unsafe because
the subsequent call to strnlen() suggests that the array need not be
nul-terminated.  If it is nul-terminated, then the call to strnlen() can be
replaced by strlen().  Either way, the code looks suspicious and diagnosing it
would be helpful.

$ cat c.c && gcc -O2 -S -Wall -Wextra c.c
char a[4];

unsigned n0, n1;

void f (void)
{
  n0 = __builtin_strlen (a);              // possibly unsafe?
  // ...
  n1 = __builtin_strnlen (a, sizeof a);   // could be replaced by strlen()?
}

Reply via email to