(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Warray-bounds-59.c
       1  /* PR middle-end/94647 - bogus -Warray-bounds on strncpy into a larger
       2     member array from a smaller array
       3     { dg-do compile }
       4     { dg-options "-O2 -Wall" } */
       5  
       6  typedef __SIZE_TYPE__ size_t;
       7  
       8  extern char* strncpy (char*, const char*, size_t);
       9  
      10  
      11  char a4[4], a8[8];
      12  
      13  void nowarn_nonmeber (void)
      14  {
      15    /* The following would deserve a warning if A4 were known not to be
      16       nul-terminated (or declared with attribute nonstring).  */
      17    strncpy (a8, a4, sizeof a8);
      18  }
      19  struct S
      20  {
      21    char a4[4], a8[8];
      22  };
      23  
      24  void nowarn_member (struct S *p, struct S *q)
      25  {
      26    /* The following would deserve a warning if A4 were known either
      27       not to be nul-terminated (e.g., declared nonstring) or to be
      28       uninitialized.  */
      29    strncpy (p->a8, p->a4, sizeof p->a8);   // { dg-bogus "\\\[-Warray-bounds" }
      30  }