[PATCH 5/7] Explicitly cast some switch parameters to enum

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

 



This patch is not trying to fix every switch, just the ones I worked
with last time, because some of these were especially unreadable.
Covers enums virDomainGraphicsType and virDomainChrType (where
applicable).

Also sort it's cases by their value.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/conf/domain_conf.c  | 22 +++++++++++++---------
 src/qemu/qemu_command.c |  4 +++-
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1bf1268..e566140 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1178,7 +1178,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
     if (!def)
         return;

-    switch (def->type) {
+    switch ((enum virDomainGraphicsType)def->type) {
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
         VIR_FREE(def->data.vnc.socket);
         VIR_FREE(def->data.vnc.keymap);
@@ -1201,6 +1201,10 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
         VIR_FREE(def->data.spice.keymap);
         virDomainGraphicsAuthDefClear(&def->data.spice.auth);
         break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
+        /* coverity[dead_error_begin] */
+        break;
     }

     for (i = 0; i < def->nListens; i++)
@@ -1575,7 +1579,7 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef *src,
     if (tgt->type != src->type)
         return false;

-    switch (src->type) {
+    switch ((enum virDomainChrType)src->type) {
     case VIR_DOMAIN_CHR_TYPE_PTY:
     case VIR_DOMAIN_CHR_TYPE_DEV:
     case VIR_DOMAIN_CHR_TYPE_FILE:
@@ -1604,16 +1608,15 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef *src,
                               tgt->data.spiceport.channel);
         break;

+    case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_STDIO:
     case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
         /* nada */
-        return true;
+        break;
     }

-    /* This should happen only on new,
-     * yet unhandled type */
-
     return false;
 }

@@ -7269,11 +7272,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     }

     switch ((enum virDomainChrType) def->type) {
-    case VIR_DOMAIN_CHR_TYPE_LAST:
     case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_STDIO:
     case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
-    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
         break;

     case VIR_DOMAIN_CHR_TYPE_PTY:
@@ -15724,11 +15727,12 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
     }
     virBufferAddLit(buf, ">\n");

-    switch (def->type) {
+    switch ((enum virDomainChrType)def->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_STDIO:
     case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
         /* nada */
         break;

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 64fd748..d89c440 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6021,7 +6021,7 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix)
     if (prefix)
         virBufferAdd(&buf, prefix, strlen(prefix));

-    switch (dev->type) {
+    switch ((enum virDomainChrType)dev->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
         virBufferAddLit(&buf, "null");
         break;
@@ -6089,7 +6089,9 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix)
                           dev->data.nix.listen ? ",server,nowait" : "");
         break;

+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
     case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
         break;
     }

-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]