https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95276
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #13 from Martin Sebor <msebor at gcc dot gnu.org> --- The latest trunk outputs the same warning with a better note (the offset is correct). As discussed in comment #7 the warning for the small test case is correct: the loop overflows the small buffer. It iterates at least three times, writing two bytes into the four byte destination in each iteration, for a total of six bytes. I don't see a bug here so I'm resolving it as invalid. If the test case below isn't representative of the fortran code please submit one that is. $ cat pr95276.c && gcc -O2 -S -Wall pr95276.c char a[4]; void f (char *s, int n) { if (n <= 2) return; char *d = a; for (int i = 0; i < n; i++) { extern volatile unsigned char h, l; *d++ = s[h]; *d++ = s[l]; } *d = '\0'; } pr95276.c: In function âfâ: pr95276.c:18:6: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 18 | *d = '\0'; | ~~~^~~~~~ pr95276.c:1:6: note: at offset 6 into destination object âaâ of size 4 1 | char a[4]; | ^