On Tue, 2022-12-13 at 20:15 +0100, Alejandro Colomar via Gcc wrote: > > > On 12/13/22 20:08, Alejandro Colomar wrote: > > Hi! > > > > For the following program: > > > > > > $ cat buf.c > > #include <stdio.h> > > > > int main(void) > > { > > char *p, buf[5]; > > > > p = buf + 6; > > printf("%p\n", p); > > } > > > > > > There are no warnings in gcc, as I would expect: > > I just re-read my text, and it is ambiguous. I meant that I expect > warnings.
Yeah, it would be good to warn about such code. Looking in bugzilla, I see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81172 which seems to talk about this issue, but that bug was closed as resolved on 2020-04-13; I'm not sure what happened here. Dave > > > > > > $ gcc -Wall -Wextra buf.c -O0 > > > > Clang does warn, however: > > > > $ clang -Weverything -Wall -Wextra buf.c -O0 > > buf.c:8:17: warning: format specifies type 'void *' but the > > argument has > > type 'char *' [-Wformat-pedantic] > > printf("%p\n", p); > > ~~ ^ > > %s > > buf.c:7:6: warning: the pointer incremented by 6 refers past > > the end of the > > array (that contains 5 elements) [-Warray-bounds-pointer- > > arithmetic] > > p = buf + 6; > > ^ ~ > > buf.c:5:2: note: array 'buf' declared here > > char *p, buf[5]; > > ^ > > 2 warnings generated. > > > > Cheers, > > > > Alex > > > > > > -- > <http://www.alejandro-colomar.es/>