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

            Bug ID: 96725
           Summary: warn for uses of global nonconstant unterminated char
                    arrays where strings are required
           Product: gcc
           Version: 11.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: ---

Although using a non-constant array initialized to all non-nul characters where
a nul-terminated string is expected doesn't necessarily imply the initializer
is  what's used, it is an indication that it might be used, and so a warning
would be helpful, especially in code that doesn't make use of const.

$ cat z.c && gcc -O2 -S -Wall -Wrestrict -fdump-tree-strlen=/dev/stdout z.c
char a[4] = { 1, 2, 3, 4 };

int f (void) { return __builtin_strlen (a); }   // warn here

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

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }
f ()
{
  long unsigned int _1;
  int _3;

  <bb 2> [local count: 1073741824]:
  _1 = __builtin_strlen (&a);
  _3 = (int) _1;
  return _3;

}

Reply via email to