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

            Bug ID: 92141
           Summary: Bogus -Wstringop-truncation warning for strncpy in a
                    loop
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: krebbel at gcc dot gnu.org
  Target Milestone: ---

Compiling the following testcase with: gcc -O2 -Wall t.c

char *strncpy(char *, const char *, long unsigned);                             
struct {                                                                        
  char b[8];                                                                    
} c[6];                                                                         
char b[8];                                                                      
void e() {                                                                      
  for (int f = 0;; f++)                                                         
    strncpy(b, c[f].b, 8);                                                      
}

gives me:

t.c: In function 'e':
t.c:8:5: warning: 'strncpy' output may be truncated copying 8 bytes from a
string of length 47 [-Wstringop-truncation]
    8 |     strncpy(b, c[f].b, 8);
      |     ^~~~~~~~~~~~~~~~~~~~~

Reply via email to