From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=38025 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsJYy-0000aq-Bt for qemu-devel@nongnu.org; Sun, 05 Sep 2010 14:03:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OsJYx-0006z6-3H for qemu-devel@nongnu.org; Sun, 05 Sep 2010 14:03:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56812) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OsJYw-0006yw-TK for qemu-devel@nongnu.org; Sun, 05 Sep 2010 14:03:31 -0400 Date: Sun, 5 Sep 2010 20:57:35 +0300 From: "Michael S. Tsirkin" Message-ID: <20100905175735.GB24336@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] Re: [PATCH 08/15] blkdebug: fix enum comparison List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel 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 > --- > 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