Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C

raw
1 // { dg-do compile }
2 // { dg-additional-options "-O2 -Wstringop-overflow=2" }
3
4 struct S {
5 char a[5];
6 void (*pf)(void);
7 };
8
9 void f (struct S *s, int n)
10 {
11 if (n < sizeof s->a + 1)
12 n = sizeof s->a + 1;
13
14 __builtin_strncpy (s->a, "123456", n); // { dg-warning "writing 6" }
15 }