[libvirt] [PATCH] maint: Fix incorrect parenthesis placement causing true/false assignment

Martin Kletzander mkletzan at redhat.com
Tue Sep 5 09:02:46 UTC 2017


On Tue, Sep 05, 2017 at 10:17:36AM +0200, Erik Skultety wrote:
>There were a few places in our code where the following pattern in 'if'
>condition occurred:
>
>if ((foo = bar() < 0))
>    do something;
>
>This patch adjusts the conditions to the expected format:
>
>if ((foo = bar()) < 0)
>    do something;
>

I'd forbid this short ugly notation.  Whoever is lazy to write:

  ...
  foo = bar();
  if (foo < 0)
  ...

is free to object until I send this e-mail.

>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1488192
>
>Signed-off-by: Erik Skultety <eskultet at redhat.com>
>---
>
>This can be especially "fun" if you try to assign multiple RNG devices to a
>domain and then try to hot-unplug any of them but the first. Anyhow I used the
>regex below to find these, I haven't spent much time tuning in, so in case
>you can come up with a better one that yields more results like these I'm all
>ears :).
>
>[[:alnum:]_]+ = [[:print:]]+[^)]) < 0))
>

I tried some other ones that would find '==' or '!=' or stuff split in
multiple lines and did not find any.

Reviewed-by: Martin Kletzander <mkletzan at redhat.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170905/55815320/attachment-0001.sig>


More information about the libvir-list mailing list