fix compilation warning (enum out of range) in winedbg

[email protected] Wed, 31 Jan 2018 03:14:53 -0600
Newsgroups gmane.comp.emulators.wine.patches
Message-ID <20180131031453.Horde.XH7hmQFpUe8KAsALpcb1tij@webmail.jetstreamsoft.com>
This message is in MIME format.

--=_P-q010fL5t6r0i1Q6UWoJV_
Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes
Content-Disposition: inline

when compiled with clang the following warning message is produced:

../../../programs/winedbg/gdbproxy.c:1586:27: warning: comparison of  
constant -1 with expression of type 'enum be_xpoint_type' is always  
true [-Wtautological-constant-out-of-range-compare]
             if (xpt->type != -1 && xpt_addr >= addr && xpt_addr <  
addr + blk_len)
                 ~~~~~~~~~ ^  ~~
../../../programs/winedbg/gdbproxy.c:2236:23: warning: comparison of  
constant -1 with expression of type 'enum be_xpoint_type' is always  
false [-Wtautological-constant-out-of-range-compare]
         if (xpt->type == -1)
             ~~~~~~~~~ ^  ~~
2 warnings generated.

compiler is free to choose underlying type as long as all defined
enum entries fit into it, so as no negative values were defined,
it can be expected to use unsigned underlying type and drop the checks.

Proposed patch adds explicit enum member with value (-1) to make sure
underlying type would have this value allowed.

Thanks,
Vlad.

--=_P-q010fL5t6r0i1Q6UWoJV_
Content-Type: text/x-diff; name=0001-Fix-compilation-warning.patch
Content-Disposition: attachment; size=2766;
 filename=0001-Fix-compilation-warning.patch

From 8b16f51ab5ffc1cc96dd6de0744d001a78af789f Mon Sep 17 00:00:00 2001
From: Vladimir Bespalov <[email protected]>
Date: Wed, 31 Jan 2018 00:37:36 -0800
Subject: [PATCH] Fix gdbproxy compilation warning

        enum underlying type is selected by the compiler to hold
        all defined elements. using an element outside the defined
        scope might lead to unwanted results.
---
 programs/winedbg/be_cpu.h   | 2 +-
 programs/winedbg/gdbproxy.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/programs/winedbg/be_cpu.h b/programs/winedbg/be_cpu.h
index 889f638ec0..d62b5177a3 100644
--- a/programs/winedbg/be_cpu.h
+++ b/programs/winedbg/be_cpu.h
@@ -20,7 +20,7 @@
 
 enum be_cpu_addr {be_cpu_addr_pc, be_cpu_addr_stack, be_cpu_addr_frame};
 enum be_xpoint_type {be_xpoint_break, be_xpoint_watch_exec, be_xpoint_watch_read,
-                     be_xpoint_watch_write};
+                     be_xpoint_watch_write, be_xpoint_free=-1};
 struct backend_cpu
 {
     const DWORD         machine;
diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c
index 7b9a4768ac..5fa48830e2 100644
--- a/programs/winedbg/gdbproxy.c
+++ b/programs/winedbg/gdbproxy.c
@@ -74,7 +74,7 @@
 
 struct gdb_ctx_Xpoint
 {
-    enum be_xpoint_type         type;   /* -1 means free */
+    enum be_xpoint_type         type;   /* (-1) == be_xpoint_free means free */
     void*                       addr;
     unsigned long               val;
 };
@@ -1583,7 +1583,7 @@ static BOOL read_memory(struct gdb_context *gdbctx, char *addr, char *buffer, SI
         {
             char *xpt_addr = xpt->addr;
 
-            if (xpt->type != -1 && xpt_addr >= addr && xpt_addr < addr + blk_len)
+            if (xpt->type != be_xpoint_free && xpt_addr >= addr && xpt_addr < addr + blk_len)
                 buffer[xpt_addr - addr] = xpt->val;
         }
     }
@@ -2192,7 +2192,7 @@ static enum packet_return packet_remove_breakpoint(struct gdb_context* gdbctx)
                                       gdbctx->process->process_io, &gdbctx->context,
                                       t, xpt->addr, xpt->val, len))
             {
-                xpt->type = -1;
+                xpt->type = be_xpoint_free;
                 return packet_ok;
             }
             break;
@@ -2233,7 +2233,7 @@ static enum packet_return packet_set_breakpoint(struct gdb_context* gdbctx)
     /* really set the Xpoint */
     for (xpt = &gdbctx->Xpoints[NUM_XPOINT - 1]; xpt >= gdbctx->Xpoints; xpt--)
     {
-        if (xpt->type == -1)
+        if (xpt->type == be_xpoint_free)
         {
             if (be_cpu->insert_Xpoint(gdbctx->process->handle,
                                       gdbctx->process->process_io, &gdbctx->context, 
-- 
2.15.1


--=_P-q010fL5t6r0i1Q6UWoJV_
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

Cg==

--=_P-q010fL5t6r0i1Q6UWoJV_--