[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] Correct use of ! and &
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH] Correct use of ! and & |
Date: |
Fri, 27 Aug 2010 11:03:56 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
"Edgar E. Iglesias" <address@hidden> writes:
> On Sat, Aug 21, 2010 at 09:42:51AM +0000, Blue Swirl wrote:
>> Combining bitwise AND and logical NOT is suspicious.
>>
>> Fixed by this Coccinelle script:
>> // From http://article.gmane.org/gmane.linux.kernel/646367
>> @@ expression E1,E2; @@
>> (
>> !E1 & !E2
>> |
>> - !E1 & E2
>> + !(E1 & E2)
>> )
>>
>> Signed-off-by: Blue Swirl <address@hidden>
>> ---
>>
>> Maybe the middle hunk should be fixed this way instead:
>> - } else if ((rw == 1) & !matching->d) {
>> + } else if ((rw == 1) && !matching->d) {
>>
>> ---
>> hw/etraxfs_eth.c | 2 +-
>> target-sh4/helper.c | 4 ++--
>> 2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
>> index b897c9c..ade96f1 100644
>> --- a/hw/etraxfs_eth.c
>> +++ b/hw/etraxfs_eth.c
>> @@ -464,7 +464,7 @@ static int eth_match_groupaddr(struct fs_eth *eth,
>> const unsigned char *sa)
>>
>> /* First bit on the wire of a MAC address signals multicast or
>> physical address. */
>> - if (!m_individual && !sa[0] & 1)
>> + if (!m_individual && !(sa[0] & 1))
>> return 0;
>
>
> Yep, the etrax part is a bug and your patch looks OK to me.
>
> Thanks
>
> Acked-by: Edgar E. Iglesias <address@hidden>
Such review is exactly what we need when static analysis spots fishy
code. Thanks!
Volunteers to look at the other two hunks?