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

            Bug ID: 102695
           Summary: missing -Wanalyzer-write-to-const for writing to
                    string, function, label, or const member
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Below are a few C test cases from my tests for the solution for pr90404 that I
noticed the analyzer doesn't issue warnings for but could and probably should.

$ cat z.c && gcc -S -Wall -fanalyzer z.c
extern void* malloc (__SIZE_TYPE__);

const char* write_strchr_literal (int x)
{
  char *p = __builtin_strchr ("123", x);
  *p = 0;   // missing warning
  return p;
}

const char* write_strchr_const_array (int x)
{
  static const char a[] = "123";
  char *p = __builtin_strchr (a, x);
  *p = 0;   // missing warning
  return a;
}

char* write_function (void)
{
  char *p = (char*)malloc /* forgot arguments */;
  __builtin_strcpy (p, "123");   // missing warning
  return p;
}

char* write_label (void)
{
  char *p = (char*)&&L;
  *p = 0;   // missing warning
L:
  return p;
}

struct A { const int i; };

extern /* not const */ struct A a;

void write_const_member (void)
{
  char *p = (char*)&a.i;
  *p = 0;   // missing warning
}

Reply via email to