qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 2/4] qga: Fix an enum conversion warningin co


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2 2/4] qga: Fix an enum conversion warningin commands-win32.c, hit by clang.
Date: Thu, 2 May 2019 16:52:37 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

On 5/2/19 4:18 PM, driver1998 wrote:
> On 5/1/19 2:25 AM, Eric Blake wrote:
>> This adds lots of explicit casts. Are they actually necessary? Without
>> seeing the actual warning, it seems fishy to have to be this explicit.
> 
> So here are the warnings, on clang version 9.0.0 (trunk 351977).
> 
> qga/commands-win32.c:461:24: error: implicit conversion from enumeration type 
> 'enum GuestDiskBusType' to different
>       enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
> [-Werror,-Wenum-conversion]
>     [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
>                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~

> qga/commands-win32.c:486:12: error: implicit conversion from enumeration type 
> 'STORAGE_BUS_TYPE'
>       (aka 'enum _STORAGE_BUS_TYPE') to different enumeration type 
> 'GuestDiskBusType' (aka 'enum GuestDiskBusType')
>       [-Werror,-Wenum-conversion]
>     return win2qemu[(int)bus];
>     ~~~~~~ ^~~~~~~~~~~~~~~~~~

Where is enum STORAGE_BUS_TYPE defined? I see GuestDiskBusType (via
qga/qapi-schema.json's 'enum':'GuestDiskBusType'), but if
STORAGE_BUS_TYPE is a type declared by some external project, we are
probably better off writing a two-way conversion table or switch
statement, rather than relying on the two enums currently happening to
have identical values (but where that might break if we accidentally
rearrange our .json QAPI file or if the external file changes their
enum).  In fact, it looks like win2qemu[] is supposed to be that table,
but it was incorrectly written.  You WANT to do:

diff --git i/qga/commands-win32.c w/qga/commands-win32.c
index d40d61f605c..6b67f16faf1 100644
--- i/qga/commands-win32.c
+++ w/qga/commands-win32.c
@@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)

 #ifdef CONFIG_QGA_NTDDSCSI

-static STORAGE_BUS_TYPE win2qemu[] = {
+static GuestDiskBusType win2qemu[] = {
     [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
     [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
     [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,

with no casts needed, either in the table or in the function that
references the table.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]