From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5Wb8-00039Q-Ij for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:59:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5Wb4-0001Jw-JJ for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:59:02 -0400 Date: Thu, 18 Jun 2015 05:58:56 -0400 (EDT) From: Frediano Ziglio Message-ID: <834587703.17443662.1434621536154.JavaMail.zimbra@redhat.com> In-Reply-To: <5581CA0E.6080906@msgid.tls.msk.ru> References: <1434028677-26160-1-git-send-email-fziglio@redhat.com> <1434028677-26160-2-git-send-email-fziglio@redhat.com> <5581CA0E.6080906@msgid.tls.msk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] Check value for invalid negative values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Tokarev Cc: qemu-trivial@nongnu.org, Gerd Hoffmann , qemu-devel@nongnu.org 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 > > --- > > 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]; > > > >