qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] Re: [PATCH 08/15] blkdebug: fix enum comparison
Date: Sun, 5 Sep 2010 20:57:35 +0300	[thread overview]
Message-ID: <20100905175735.GB24336@redhat.com> (raw)
In-Reply-To: <AANLkTinugXTY2ySY3DLk4KoBW_FDvf2mTxw3KZZqS81p@mail.gmail.com>

On Sun, Sep 05, 2010 at 03:06:32PM +0000, Blue Swirl wrote:
> The signedness of enum types depend on the compiler implementation.
> Therefore the check for negative values may or may not be meaningful.
> 
> Fix by explicitly casting to a signed integer.
> 
> Since the values are also checked earlier against event_names
> table, this is an internal error. Change the 'if' to 'assert'.
> 
> This also fixes a warning with GCC flag -Wtype-limits.
> 
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> ---
>  block/blkdebug.c |    4 +---
>  1 files changed, 1 insertions(+), 3 deletions(-)
> 
> diff --git a/block/blkdebug.c b/block/blkdebug.c
> index 2a63df9..4d6ff0a 100644
> --- a/block/blkdebug.c
> +++ b/block/blkdebug.c
> @@ -439,9 +439,7 @@ static void blkdebug_debug_event(BlockDriverState
> *bs, BlkDebugEvent event)
>      struct BlkdebugRule *rule;
>      BlkdebugVars old_vars = s->vars;
> 
> -    if (event < 0 || event >= BLKDBG_EVENT_MAX) {
> -        return;
> -    }
> +    assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);

I am not sure all compilers must generate a negative value from
a very large unsigned integer cast to int.

assert((unsigned)event < BLKDBG_EVENT_MAX);

will do the same but without integer overflow.

> 
>      QLIST_FOREACH(rule, &s->rules[event], next) {
>          process_rule(bs, rule, &old_vars);
> -- 
> 1.6.2.4

  reply	other threads:[~2010-09-05 18:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-05 15:06 [Qemu-devel] [PATCH 08/15] blkdebug: fix enum comparison Blue Swirl
2010-09-05 17:57 ` Michael S. Tsirkin [this message]
2010-09-05 19:37   ` [Qemu-devel] " Blue Swirl
2010-09-05 21:00     ` [Qemu-devel] Re: [PATCH 08/15] blkdebug: fix enum comparison' Michael S. Tsirkin

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=20100905175735.GB24336@redhat.com \
    --to=mst@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).