All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frediano Ziglio <fziglio@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 2/2] Check value for invalid	negative values
Date: Thu, 18 Jun 2015 05:58:56 -0400 (EDT)	[thread overview]
Message-ID: <834587703.17443662.1434621536154.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <5581CA0E.6080906@msgid.tls.msk.ru>

For the same reason there is the v >= l test.
The v >= l test state that the value can be out of range so it not always a constant in the range.
Adding the v < 0 check for every invalid value. As these are executed only for logging should not be a performance penalty.
I also hope the compiler is able to optimize

if (v < 0 || v >= l)

with 

if ((unsigned) v >= l)

Frediano

> 
> 11.06.2015 16:17, Frediano Ziglio wrote:
> > In qxl_v2n check that value is not negative.
> 
> Why do you think it is necessary?
> 
> Thanks,
> 
> /mjt
> 
> > Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> > ---
> >  hw/display/qxl-logger.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/hw/display/qxl-logger.c b/hw/display/qxl-logger.c
> > index d944d3f..faed869 100644
> > --- a/hw/display/qxl-logger.c
> > +++ b/hw/display/qxl-logger.c
> > @@ -93,7 +93,7 @@ static const char *const spice_cursor_type[] = {
> >  
> >  static const char *qxl_v2n(const char *const n[], size_t l, int v)
> >  {
> > -    if (v >= l || !n[v]) {
> > +    if (v < 0 || v >= l || !n[v]) {
> >          return "???";
> >      }
> >      return n[v];
> 
> 
> 
> 


WARNING: multiple messages have this Message-ID (diff)
From: Frediano Ziglio <fziglio@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] Check value for invalid	negative values
Date: Thu, 18 Jun 2015 05:58:56 -0400 (EDT)	[thread overview]
Message-ID: <834587703.17443662.1434621536154.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <5581CA0E.6080906@msgid.tls.msk.ru>

For the same reason there is the v >= l test.
The v >= l test state that the value can be out of range so it not always a constant in the range.
Adding the v < 0 check for every invalid value. As these are executed only for logging should not be a performance penalty.
I also hope the compiler is able to optimize

if (v < 0 || v >= l)

with 

if ((unsigned) v >= l)

Frediano

> 
> 11.06.2015 16:17, Frediano Ziglio wrote:
> > In qxl_v2n check that value is not negative.
> 
> Why do you think it is necessary?
> 
> Thanks,
> 
> /mjt
> 
> > Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> > ---
> >  hw/display/qxl-logger.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/hw/display/qxl-logger.c b/hw/display/qxl-logger.c
> > index d944d3f..faed869 100644
> > --- a/hw/display/qxl-logger.c
> > +++ b/hw/display/qxl-logger.c
> > @@ -93,7 +93,7 @@ static const char *const spice_cursor_type[] = {
> >  
> >  static const char *qxl_v2n(const char *const n[], size_t l, int v)
> >  {
> > -    if (v >= l || !n[v]) {
> > +    if (v < 0 || v >= l || !n[v]) {
> >          return "???";
> >      }
> >      return n[v];
> 
> 
> 
> 

  reply	other threads:[~2015-06-18  9:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11 13:17 [Qemu-trivial] [PATCH 1/2] Constify some variable Frediano Ziglio
2015-06-11 13:17 ` [Qemu-devel] " Frediano Ziglio
2015-06-11 13:17 ` [Qemu-trivial] [PATCH 2/2] Check value for invalid negative values Frediano Ziglio
2015-06-11 13:17   ` [Qemu-devel] " Frediano Ziglio
2015-06-17 19:27   ` [Qemu-trivial] " Michael Tokarev
2015-06-17 19:27     ` [Qemu-devel] " Michael Tokarev
2015-06-18  9:58     ` Frediano Ziglio [this message]
2015-06-18  9:58       ` Frediano Ziglio
2015-06-18 10:18       ` [Qemu-trivial] [Qemu-devel] " Gerd Hoffmann
2015-06-18 10:18         ` [Qemu-devel] [Qemu-trivial] " Gerd Hoffmann
2015-06-18 10:45         ` [Qemu-trivial] [Qemu-devel] " Frediano Ziglio
2015-06-18 10:45           ` [Qemu-devel] [Qemu-trivial] " Frediano Ziglio
2015-06-18 13:56           ` [Qemu-trivial] [Qemu-devel] " Gerd Hoffmann
2015-06-18 13:56             ` [Qemu-devel] [Qemu-trivial] " Gerd Hoffmann
2015-06-17 19:23 ` [Qemu-trivial] [PATCH 1/2] Constify some variable Michael Tokarev
2015-06-17 19:23   ` [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=834587703.17443662.1434621536154.JavaMail.zimbra@redhat.com \
    --to=fziglio@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mjt@tls.msk.ru \
    --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.