Skip to contentSkip to conversation

Matching Function Pointer

Cocci Mitchell Cuddie 2 participants 2 messages Sep 4, 2014

lore
Share & tools
lore
#0 lore raw

Julia,

I am putting together a patch to find instances of a switch on a pointer typed argument. The patch below seems to work unless the argument is a function pointer in which case it doesn't match. How does one match a function pointer.

Secondly is there a way to have it mark if x is any type other than int?

@r@
expression *x; type t; position p1;
@@
* switch ((t)x)

 {
    case ...:@p1
        ...

}

Mitchell

#1 lore raw
Quoted 6 lines · Mitchell Cuddie

Julia,

I am putting together a patch to find instances of a switch on a pointer typed argument. The patch below seems to work unless the argument is a function pointer in which case it doesn't match. How does one match a function pointer.

A function pointer shouldn't matter. Check your code with spatch --parse-c. Perhaps it is not parsing the containing function for some other reason.

Quoted 1 line

Secondly is there a way to have it mark if x is any type other than int?

You can use two rules:

@bad@
int x; type t;
position p;
@@

switch at p ((t)x) { ... }

@r@
expression x; type t;
position p != bad.p;
@@

*switch at p ((t)x)
{ ... } // put your case pattern here

julia

Quoted 17 lines

@r@
expression *x; type t; position p1;
@@
* switch ((t)x)

 {
    case ...:@p1
        ...

}

Mitchell

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci