[libvirt] [PATCH] conf: check rombar against VIR_DOMAIN_TRISTATE_SWITCH_ABSENT

Pavel Hrdina phrdina at redhat.com
Mon Aug 7 15:30:42 UTC 2017


On Mon, Aug 07, 2017 at 05:06:49PM +0200, Michal Privoznik wrote:
> On 08/07/2017 04:56 PM, Ján Tomko wrote:
> > Make the comparison explicit.
> > ---
> >  src/conf/domain_conf.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> > index 3cdb5e348..b5ce2ecd9 100644
> > --- a/src/conf/domain_conf.c
> > +++ b/src/conf/domain_conf.c
> > @@ -5359,10 +5359,10 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
> >      }
> >  
> >      if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM) &&
> > -        (info->rombar || info->romfile)) {
> > +        (info->rombar != VIR_TRISTATE_SWITCH_ABSENT || info->romfile)) {
> >  
> >          virBufferAddLit(buf, "<rom");
> > -        if (info->rombar) {
> > +        if (info->rombar != VIR_TRISTATE_SWITCH_ABSENT) {
> >              const char *rombar = virTristateSwitchTypeToString(info->rombar);
> >  
> >              if (rombar)
> > 
> 
> I'm not against this patch, it's just that we set ABSENT explicitly to
> zero value so that we can do shortcuts like this. If we don't want to
> have them, we ought to remove the explicit value assignment.

The shortcut is nice, but I don't like it personally.  If the variable
can contain more than two states I'd rather check it explicitly.  That's
why I prefer (int == 0) over (!int).

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170807/d77a4d23/attachment-0001.sig>


More information about the libvir-list mailing list