[cfe-dev] no warning for arrays that are too short?

Jordan Rose jordan_rose at apple.com
Wed Dec 5 18:07:56 PST 2012


If you want checking of array parameter bounds, you have to say "double arg[static 4]".

It's kind of bizarre, but I imagine it comes from people using array typedefs as parameters and C99 not wanting to mess with those.

Jordan


On Dec 5, 2012, at 17:24 , Sean McBride <sean at rogue-research.com> wrote:

> Hi all,
> 
> I was sad to discover that the compiler does not warn here:
> 
> ---------
> static void Set4 (const double arg[4])
> {
> 	printf("%f %f %f %f \n", arg[0], arg[1], arg[2], arg[3]);
> }
> 
> int main (void)
> {
> 	double array[3] = {1.0, 2.0, 3.0};
>  Set4(array);
> 	return 0;
> }
> ---------
> 
> I'm admittedly naive, but I would have thought it could see that the passed array has fewer elements than the function expects...
> 
> Cheers,
> 
> Sean
> 
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list