On Thu, 4 Nov 2010, Vasiliy Kulikov wrote:

> On Thu, Nov 04, 2010 at 17:06 +0100, Julia Lawall wrote:
> > On Thu, 4 Nov 2010, Vasiliy Kulikov wrote:
> > > IMO it should catch all C99 arrays, correct?
> > 
> > I'm not an expert on what a C99 array is.  But if it is the case where the 
> > size is not a constant,
> 
> Exactly.
> 
> > then this looks fine.
> > I think  you don't really 
> > need TT.  You could just say constant s, unless you need the type for 
> > something else.
> 
> Correct, thank you.
> 
> > > Obviously 1+1 is constant :)
> > 
> > I think this is something that has gone back and forth.  Is it a big 
> > problem in practice?
> 
> Actually, I want to inspect all C99 array usages as they might be
> dangerous if array size is not correctly checked.  If 1+1 is not
> constant, I would get just more code to manually check.  It's not
> horrible, but I'd want to avoid it ;)
> 
> Do you mean that to implement it properly you have to change too many
> boring cases of arithmetic operators?  If so, don't trouble yourself.

No, I don't think it is hard to implement.  I think that at some point I 
didn't want that to be a constant, only "atomic constants".  And then with 
constant matching any expression that only involves constants, it
was hard to specify a pattern for atomic constants.

I guess I could have an atomic constant metavariable declaration?  Or 
maybe constexpression (like idexpression) for something that can also 
match a more complex expression involving only constants?

Or if you find that some case such as + is common, then you could easily 
add that into your ( | ), to cause it to be ignored.  It would be
<+... E1 + E2 ...+>.  If it doesn't parse, put parentheses around the 
<+... ...+>.

> Also, defined constant is not constant too:
> 
> --- main.c  2010-11-04 19:04:39.000000000 +0300
> +++ /tmp/cocci-output-16573-ef1775-main.c   2010-11-04
> 19:04:41.000000000 +0300
> @@ -11,9 +11,6 @@ main(int argc, char **argv)
>  {
>      int s = 2;
>      int a[sizeof(int)];
> -    int b[s];
> -    int c[1+1];
>  #define  size 1
> -    int d[size];
>      return 0;
>  }

Again, this could be viewed as a design decision, but it was one that I 
didn't really think about.  You should be able to add more to the ( | ) to 
get rid of this problem as well.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to