Skip to contentSkip to conversation

[4844] Avoid compiler warning.

Qemu-devel Thiemo Seufer 3 participants 3 messages Jul 3, 2008 – Jul 4, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 4844

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4844
Author:   ths
Date:     2008-07-03 21:36:35 +0000 (Thu, 03 Jul 2008)

Log Message:
-----------
Avoid compiler warning.

Modified Paths:
--------------
trunk/cpu-all.h

Modified: trunk/cpu-all.h
===================================================================

cpu-all.h +1 -1
@@ -667,7 +667,7 @@
 
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
-#define h2g(x) ((target_ulong)(x - GUEST_BASE))
+#define h2g(x) ((target_ulong)((unsigned long)(x) - GUEST_BASE))
 
 #define saddr(x) g2h(x)
 #define laddr(x) g2h(x)
#1 lore raw
Quoted 1 line · Thiemo Seufer

Revision: 4844

[...]

Review

Quoted 2 lines
(quoted diff) +1 -1
-#define h2g(x) ((target_ulong)(x - GUEST_BASE))
+#define h2g(x) ((target_ulong)((unsigned long)(x) - GUEST_BASE))

What about getting rid of explicit casts when using h2g?

Laurent

syscall.c +2 -2
Index: linux-user/syscall.c
===================================================================
@@ -2018,7 +2018,7 @@
                 ret = get_errno((long)host_addr);
                 break;
             }
-            raddr = h2g((unsigned long)host_addr);
+            raddr = h2g(host_addr);
             /* find out the length of the shared memory segment */
             
             ret = get_errno(shmctl(first, IPC_STAT, &shm_info));
@@ -2477,7 +2477,7 @@
         if (!ldt_table)
             return -TARGET_ENOMEM;
         memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
-        env->ldt.base = h2g((unsigned long)ldt_table);
+        env->ldt.base = h2g(ldt_table);
         env->ldt.limit = 0xffff;
     }
 
main.c +1 -1
Index: linux-user/main.c
===================================================================
@@ -2472,7 +2472,7 @@
     {
         uint64_t *gdt_table;
         gdt_table = qemu_mallocz(sizeof(uint64_t) * TARGET_GDT_ENTRIES);
-        env->gdt.base = h2g((unsigned long)gdt_table);
+        env->gdt.base = h2g(gdt_table);
         env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
 #ifdef TARGET_ABI32
         write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
#2 lore raw
In reply to Thiemo Seufer
Quoted 18 lines · Thiemo Seufer

Revision: 4844

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4844
Author:   ths
Date:     2008-07-03 21:36:35 +0000 (Thu, 03 Jul 2008)

Log Message:
-----------
Avoid compiler warning.

Modified Paths:
--------------
trunk/cpu-all.h

Modified: trunk/cpu-all.h
===================================================================

cpu-all.h line 670

Quoted 5 lines
cpu-all.h +1 -1
@@ -667,7 +667,7 @@
 
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
-#define h2g(x) ((target_ulong)(x - GUEST_BASE))
+#define h2g(x) ((target_ulong)((unsigned long)(x) - GUEST_BASE))

Just to keep heads up: While this is OK in itself, the potential bug it pointed out is still open, see

http://permalink.gmane.org/gmane.comp.emulators.qemu/26687

Jan