Pointer arithmetic not detected by -Wall
Pavel Roskin
pavel_roskin@geocities.com
Wed Mar 29 16:13:00 GMT 2000
Hello!
gcc-2.95.2 doesn't detect some very suspicious uses of pointer arithmetic
by default. This progam causes no warnings:
void* func()
{
void *prt = 0;
return prt++;
}
even if compiled by:
gcc -c -W -Wall bad.c
I need to specify -Wpointer-arith to get the warning. Most people believe
that -Wall covers all the cases that can and should be avoided as long as
gcc can detect them.
Incrementing void pointers is really bad. HP-UX native CC doesn't even
compile it. I can imagine compilers that add other value than 1, also "for
convenience". This means that the risk of generating bad code is very
high.
I suggest adding -Wpointer-arith to the flags turned on by -Wall.
Regards,
Pavel Roskin
More information about the Gcc
mailing list