https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- An even simpler test case. Changing the index in g() to unsigned avoids the warning. $ cat pr92955.c && gcc -O3 -S -Wall pr92955.c typedef struct S { unsigned char n, a[4]; } S; void f (S *s, const unsigned char *p, int n) { int i = n < 0 ? 0 : n; while (*p) s->a[i++] = *p++; // no warning (good) } void g (S *s, const unsigned char *p, int n) { int i; for (i = 0; i < n; ++i); while (*p) s->a[i++] = *p++; // spurious -Wstringop-overflow } pr92955.c: In function āgā: pr92955.c:18:15: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 18 | s->a[i++] = *p++; // spurious -Wstringop-overflow | ~~~~~~~~~~^~~~~~ pr92955.c:1:37: note: at offset [4, 2147483647] to object āaā with size 4 declared here 1 | typedef struct S { unsigned char n, a[4]; } S; | ^