On Thu, Jul 1, 2010 at 2:28 AM, Julia Lawall <[email protected]> wrote:
> It should also be possible to do this using T1 multiple times.  For
> example, for the declaration case, you could write:
>
> @r@
> type T1,T2;
> identifier c;
> position p;
> @@
>
> (
> T1 *c = calloc(sizeof(T1),...);
this one is a correct declaration.

> |
> T1 *...@p = calloc(sizeof(T2),...);
> )
>
> You can of course extend it to take into account the other cases you have
> considered.

I think you intended to use this one:
(
T1 *...@p = calloc(sizeof(*b), ...);
|
T1 *...@p = calloc(sizeof(T2), ...);
)

This doesn't work neither. It says this declaration is wrong, which is
obviously not:

        struct b *b = calloc(sizeof(*b), 1);

For the file attached previously and removing the "if t1 != t2" in
python, it prints:

WARNING: wrong size to calloc function => test-coccinelle-wrong-alloc.c:18
         Type is 'struct b', but 'sizeof(struct b)' was allocated
WARNING: wrong size to calloc function => test-coccinelle-wrong-alloc.c:19
         Type is 'struct a', but 'sizeof(struct b)' was allocated

>
> For Linux, I made the following rule, which finds problems when the size
> computation is more complicated:
>
> @r@
> type T;
> T *x;
> position p;
> @@
>
> x...@p = <+...sizeof(T)...+>
>
> @s@
> expression x;
> position p;
> @@
>
> x...@p = <+...sizeof(*x)...+>
>
> @bad@
> position p!={r.p,s.p};

Ahn... ok, this is indeed better than what I did. Write rules for the
good cases and another one for the bad ones, right?

> type T, T1, T2;
> T1 *x;
> T2 **y;
> typedef u8;
> {void *, char *, unsigned char *, u8*} a;
> {struct device,struct net_device} dev;
> @@
>
> (
> y = \(kmalloc\|kzalloc\)(<+...sizeof(T)...+>,...)
> |
> a = \(kmalloc\|kzalloc\)(<+...sizeof(T)...+>,...)
> |
> x...@p = \(kmalloc\|kzalloc\)(<+...sizeof(T)...+>,...)
> )


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

Reply via email to