Patchwork [08/15] blkdebug: fix enum comparison

login
register
mail settings
Submitter Blue Swirl
Date Sept. 10, 2010, 8:59 p.m.
Message ID <AANLkTim1QodsmiHayA4NT_KnY1EfzpQy-0EoBs1WnG2S@mail.gmail.com>
Download mbox | patch
Permalink /patch/64467/
State New
Headers show

Comments

Blue Swirl - Sept. 10, 2010, 8:59 p.m.
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 avoids 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(-)

         process_rule(bs, rule, &old_vars);

Patch

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);

     QLIST_FOREACH(rule, &s->rules[event], next) {