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(a)redhat.com>
---
src/rpc/virnetlibsshsession.c | 4 ++++
src/rpc/virnetservermdns.c | 5 ++++-
src/rpc/virnetsshsession.c | 8 ++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 25f93cec97..25d65878b2 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -880,6 +880,10 @@ virNetLibsshAuthenticate(virNetLibsshSessionPtr sess)
/* try to authenticate with password */
ret = virNetLibsshAuthenticatePassword(sess, auth);
break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected SSH auth method %d"),
auth->method);
+ return -1;
}
if (ret == SSH_AUTH_ERROR) {
diff --git a/src/rpc/virnetservermdns.c b/src/rpc/virnetservermdns.c
index 0a2bc87322..7e3b7e632a 100644
--- a/src/rpc/virnetservermdns.c
+++ b/src/rpc/virnetservermdns.c
@@ -133,6 +133,7 @@ static void virNetServerMDNSGroupCallback(AvahiEntryGroup *g
ATTRIBUTE_UNUSED,
case AVAHI_ENTRY_GROUP_UNCOMMITED:
case AVAHI_ENTRY_GROUP_REGISTERING:
+ default:
;
}
}
@@ -249,7 +250,9 @@ static void virNetServerMDNSClientCallback(AvahiClient *c,
case AVAHI_CLIENT_CONNECTING:
VIR_DEBUG("Client connecting.... %p", mdns->client);
- ;
+ break;
+ default:
+ break;
}
}
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index e742175654..40256d0f9a 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -813,6 +813,10 @@ virNetSSHAuthenticateKeyboardInteractive(virNetSSHSessionPtr sess,
case VIR_NET_SSH_AUTHCB_OK:
/* everything went fine, let's continue */
break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected SSH auth code %d"),
sess->authCbErr);
+ return -1;
}
if (ret == 0)
@@ -897,6 +901,10 @@ virNetSSHAuthenticate(virNetSSHSessionPtr sess)
if (strstr(auth_list, "password"))
ret = virNetSSHAuthenticatePassword(sess, auth);
break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected SSH auth method %d"),
auth->method);
+ return -1;
}
/* return on success or error */
--
2.14.3