All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] vnc: fix "info vnc" with "-vnc ..., reverse=on"
Date: Tue, 16 Oct 2012 10:33:23 +0400	[thread overview]
Message-ID: <507CFFB3.7070907@msgid.tls.msk.ru> (raw)
In-Reply-To: <1349872258-21952-1-git-send-email-pbonzini@redhat.com>

On 10.10.2012 16:30, Paolo Bonzini wrote:
[]
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -372,6 +372,10 @@ VncInfo *qmp_query_vnc(Error **errp)
>              }
>          }
>  
> +        if (vnc_display->lsock == -1) {

FWIW, can't we use "< 0" condition in all cases like this - for
testing whenever a filedescriptor is not open or if a system call
returned failure?  Why we compare with -1 only?  The "< 0" comparison
is cheaper in the resulting code (very very small difference), but
more to the point, it guarantees that no invalid value is treated
as valid - for example, in case some function returns -errno like
it was with bdrv_something() recently.  I use "< 0" in such places
for over 20 years for this reason, this "technique" saved me
countless number of times, when old API changed, or when I switched
to a new API without reviewing return value checking in all places,
or when I just didn't read the manpage carefully... ;)

Thanks,

/mjt


WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] vnc: fix "info vnc" with "-vnc ..., reverse=on"
Date: Tue, 16 Oct 2012 10:33:23 +0400	[thread overview]
Message-ID: <507CFFB3.7070907@msgid.tls.msk.ru> (raw)
In-Reply-To: <1349872258-21952-1-git-send-email-pbonzini@redhat.com>

On 10.10.2012 16:30, Paolo Bonzini wrote:
[]
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -372,6 +372,10 @@ VncInfo *qmp_query_vnc(Error **errp)
>              }
>          }
>  
> +        if (vnc_display->lsock == -1) {

FWIW, can't we use "< 0" condition in all cases like this - for
testing whenever a filedescriptor is not open or if a system call
returned failure?  Why we compare with -1 only?  The "< 0" comparison
is cheaper in the resulting code (very very small difference), but
more to the point, it guarantees that no invalid value is treated
as valid - for example, in case some function returns -errno like
it was with bdrv_something() recently.  I use "< 0" in such places
for over 20 years for this reason, this "technique" saved me
countless number of times, when old API changed, or when I switched
to a new API without reviewing return value checking in all places,
or when I just didn't read the manpage carefully... ;)

Thanks,

/mjt

  parent reply	other threads:[~2012-10-16  6:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-10 12:30 [Qemu-trivial] [PATCH] vnc: fix "info vnc" with "-vnc ..., reverse=on" Paolo Bonzini
2012-10-10 12:30 ` [Qemu-devel] " Paolo Bonzini
2012-10-12  8:55 ` [Qemu-trivial] " Stefan Hajnoczi
2012-10-12  8:55   ` [Qemu-devel] " Stefan Hajnoczi
2012-10-16  6:33 ` Michael Tokarev [this message]
2012-10-16  6:33   ` [Qemu-devel] " Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=507CFFB3.7070907@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.