On Fri, Sep 18, 2020 at 9:17 AM Gustavo A. R. Silva <gustavoars@xxxxxxxxxx> wrote: > > This bug could have been prevented by either adopting better > coding practices or through the use[3] of the recent struct_size() helper. Well, my unspoken point was that coding practices are just theoretical. Coding practices don't help - actual *checking* of them helps. I realize that structures with flexible-array member are allowed to use sizeof() in standard C, but if we want to make sure this doesn't happen, we would need to have a stricter model than that. But a quick google didn't find any flag to enable such a stricter mode. I guess a sparse warning would work, but sparse already has too many warnings and as a result most people don't care - even if they were to run sparse in the first place. Is there some gcc option that I didn't find to help find any questionable cases? Because if we have a coding practice that you should use 'struct_size()', then we should also have a way to _verify_ that. The whole - and really ONLY - point of using flexible arrays was that it would protect against these things. And as things are now, it simply doesn't. It's not an actual improvement over just using a zero-sized array. (Slightly related: copying a struct has the exact same issue. A flexible array is no better than a zero-sized array, and generates the same code and the same lack of any warnings, afaik). Linus