This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A new check ?


I'm thinking of adding a new check to gcc.

There's fairly common code that looks like:


{
char buffer[50];

snprintf(buffer, sizeof(buffer), fmt, ...);
or
read(fd, buffer, sizeof(buffer))...
well, you get the idea,
}

You will probably notice snprintf right away, but read will be worse,
as it will just read a file in small chunks instead of large pieces, for
instance.

Then, later on, someone comes back and change the array to a dynamically
allocated char *.

All of a sudden, you get sizeof(char *).

I was thinking along the lines of an attribute say
snprintf() __attribute__((buffer(1, 2))
read() __attribute__((buffer(2, 3))

I hope that I can get back enough type information at that point to
distinguish between the pointer and the array proper...
It might be necessary to track sizeofs up to that point, which I don't
know whether gcc already does or not.

Does this look like a good idea ?

Does this look implementable ?
-- 
	Marc Espie		
|anime, sf, juggling, unicycle, acrobatics, comics...
|AmigaOS, OpenBSD, C++, perl, Icon, PostScript...
| `real programmers don't die, they just get out of beta'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]