Some constructs cause gcc to warn as always causing a buffer overflow incorrectly. For example, this is a minimalistic version of a warning found in wine-1.3.2: ---------- #include <string.h> #include <stdlib.h> #include <stdint.h> struct T { union { struct { char str[1]; } x; } u; }; int main() { struct T *p = malloc(sizeof(char) * 100); strcpy(p->u.x.str, "ABCD"); return 0; } ---------- This is a slightly obfuscated version of the struct hack and is clearly not a buffer overflow. Yet compiling with: "gcc -O2 test.c -o test" results in: In file included from /usr/include/string.h:640:0, from test.c:2: In function 'strcpy', inlined from 'main' at test.c:16:8: /usr/include/bits/string3.h:107:3: warning: call to __builtin___strcpy_chk will always overflow destination buffer
This is intentional, considering this as a flexible array member is already way too over what should be allowed. Either use a true flexible array member, or use memcpy instead (which isn't limited to field boundaries, only to object boundaries).