While on the list ... In some pieces of code I've found incorrect
patterns like that:
if (x != 5 || x != 6)
I've came up with the following cocci file:
@
expression x, y, z;
@
- x != y || ... x != z [ or x != y || ... || x != z, writing from memory]
It would be the second one. You have to repeat the ||.
+ x != y && x != z
is that the best I could do?
As you can see, it generates incorrect patches when there are multiple
||.
I'm not sure what answer you expect when there are multiple ||. If there
are other things in the ... position, it is not necessarily correct to
turn all of the ||s into &&s. It might be a good idea to first transform
the cases with one ||, and then use * in the leftmost column to look at
the cases where there is more than one || to see what would be best to do.
Moreover, it generates incorrect patches for:
0 != x || 0 != y
It's not something I can't live with, but maybe there's better
alternative?
It looks like you want to ensure that x is not a constant? For that you
can have a disjunction:
@@
constant c;
expression x,y,z;
@@
(
c != y || c != z
|
- x != y || x != z
+ x != y && x != z
)
Note that the commutativity isomorphism for != only works when one
argument is a constant. So you would either want to make your own more
general isomorphism (look for examples containing the keyword using, which
lets you include your own isomorphism file) or make some more variants
explicitly.
julia
Something more ... general? I've looked through sample
patch sets and couldn't find anything relevant.
I could write constant y, z;, but that would prevent me from detecting
if (x != a(5) || x != a(6)).
Best regards,
Robert
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)