[Cocci] Using spatch to find potential errors in C code
Diego Liziero
diegoliz at gmail.com
Tue Apr 14 04:47:42 CEST 2009
On Mon, Apr 13, 2009 at 10:08 PM, Julia Lawall <julia at diku.dk> wrote:
>>
>> And I think this should be reported by you as you found it.
>
> Well, it was your idea in the beginning :). And the != solution is
> clearly better than !(...).
>> - while ((!(MemReadHSCX(cs, hscx, HSCX_STAR) & 0x44) == 0x40) && to) {
>> + while ((!((MemReadHSCX(cs, hscx, HSCX_STAR) & 0x44) == 0x40)) && to) {
>
> This one is a real bug, right?
>
>> - if (!atomic_inc_return(&pMds->TxThreadCount) == 1)
>> + if (!(atomic_inc_return(&pMds->TxThreadCount) == 1))
>
> This one too?
I think so. Just sent all of them to kernel-janitors and maintainer,
hoping I understood how things should be done.
>> And, as regards false positives, if there is a common pattern (such as
>> !E == 0), is there a way to exclude it in the semantic patch?
>
> Using a disjunction. The better rule would seem to be:
>
> @disable is_zero@
> expression E;
> constant C;
> @@
>
> (
> E == 0
> |
> - !E == C
> + E != C
> )
>
> The disable is_zero part is to keep Coccinelle from considering !E, which
> is semantically equivalent to E == 0, but not really the issue here.
I see. I think I should learn better how Coccinelle works, it's really powerful.
Thanks for your help,
Diego.
More information about the Cocci
mailing list