[PATCH v2 38/42] daemon: add default: case to all switch statements

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

 



Even if the compiler has validated that all enum constants have case
statements in a switch, it is not safe to omit a default: case
statement. When assigning a value to a variable / struct field that is
defined with an enum type, nothing prevents an invalid value being
assigned. So defensive code must assume existance of invalid values and
thus all switches should have a default: case.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 daemon/libvirtd.c | 4 ++--
 daemon/remote.c   | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index c5bb12b8ce..4944633c57 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -290,9 +290,9 @@ static int daemonErrorLogFilter(virErrorPtr err, int priority)
     case VIR_ERR_NO_SERVER:
     case VIR_ERR_NO_CLIENT:
         return VIR_LOG_DEBUG;
+    default:
+        return priority;
     }
-
-    return priority;
 }
 
 
diff --git a/daemon/remote.c b/daemon/remote.c
index 6de4bd00d4..51740e7b10 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -3288,6 +3288,10 @@ remoteDispatchAuthList(virNetServerPtr server,
     case VIR_NET_SERVER_SERVICE_AUTH_SASL:
         ret->types.types_val[0] = REMOTE_AUTH_SASL;
         break;
+    default:
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unexpected auth method %d"), auth);
+        goto cleanup;
     }
 
     rv = 0;
-- 
2.14.3

--
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]

  Powered by Linux