On Wed, Sep 7, 2016 at 2:03 AM, Paul Eggert <egg...@cs.ucla.edu> wrote: > With a char[] flexible array member in a struct with nontrivial > alignment, GCC-generated code can access past the end of the > array, because GCC assumes there are padding bytes to get the > struct aligned. So the common idiom of malloc (offsetof (struct > s, m), n) does not properly allocate an n-byte trailing member, as > malloc’s argument should be the next multiple of alignof (struct s). > See GCC Bug#66661: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66661 > Although C11 apparently permits this GCC optimization (i.e., there > was a bug in Gnulib not in GCC), possibly this is a defect in C11. > See the thread containing: > https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00317.html > * lib/flexmember.h: New file.
Ouch. I'm glad this doesn't happen often. Thanks!