[libvirt] [PATCH] macvtap.c: add parenthesis for similar expressions

Eric Blake eblake at redhat.com
Thu Feb 3 18:28:36 UTC 2011


On 02/03/2011 11:12 AM, Davidlohr Bueso wrote:
> It wouldn't hurt to add some parenthesis in the following two similar expression for better readability.

I take it you were using some gcc option about precedence of operations
being confusing between ! and <; including that gcc warning message in
your commit message can aid the discussion.

> 
> ---
>  src/util/macvtap.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/util/macvtap.c b/src/util/macvtap.c
> index 09d7b78..92147ab 100644
> --- a/src/util/macvtap.c
> +++ b/src/util/macvtap.c
> @@ -1048,8 +1048,8 @@ doPortProfileOpSetLink(bool nltarget_kernel,
>  
>              memcpy(ifla_vf_mac.mac, macaddr, 6);
>  
> -            if (!nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
> -                &ifla_vf_mac) < 0)
> +            if ((!nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac), 
> +                &ifla_vf_mac)) < 0)

The indentation is wrong, too; the &ifla... of the second line should
line up just after nla_put( of the first line.  That was botched in
December by commit 013c000 when the lines were reindented.

Actually, you've uncovered a bigger bug, but didn't fix it right.

Here, 'expr' is 'nla_put(...)'.  But '!expr < 0' will never be true.
('!expr' is either 0 or 1, which is always non-negative).  We either
meant 'expr < 0' or '!expr', but not both (or maybe we meant '!(expr <
0)', which is easier if written 'expr >= 0').  The bug has existed since
Stefan's commit 77e7c13 in November; and looking at the rest of that
commit, it _looks_ like we meant to use 'expr < 0' (that is, the correct
fix is to delete !), but I'd like confirmation from Stefan.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110203/7a6b9e65/attachment-0001.sig>


More information about the libvir-list mailing list