[Bug middle-end/93582] [10 Regression] -Warray-bounds gives error: array subscript 0 is outside array bounds of struct E[1]
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Feb 4 21:17:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93582
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Adam Jackson from comment #5)
> (In reply to Martin Sebor from comment #4)
> > It seems like the reporter might be conflating the forming of a past-the-end
> > pointer (what the GRABEXT macro does) with dereferencing that pointer (the
> > use of the -> operator with the result).
>
> I'm not conflating it, I'm pretty sure the whole point of computing that
> address
> is to dereference it because that's where the data I want is. The caller is
> doing somemthing of the form:
>
> struct image {
> int w, h, bpp;
> // unsigned char pixels[];
> };
>
> struct image *i = malloc(sizeof(*i) + w * h * bpp);
>
> This is not uncommon in code older than zero-length arrays.
Well, zero-length arrays are a GNU C extension, but pre-C99 you could use
pixels[1] and post-C99 you can use pixels[]. Is non of that an option?
More information about the Gcc-bugs
mailing list