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/bhyve/bhyve_command.c | 12 ++++++++++--
src/libvirt_private.syms | 2 ++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index c1241b8110..ad6775ebc8 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -420,9 +420,17 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
virBufferAsprintf(&opt, ":%d", graphics->data.vnc.port);
break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported listen type %s"),
+ virDomainGraphicsListenTypeToString(glisten->type));
+ goto error;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
default:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("Unsupported listen type"));
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected graphics listen type %d"),
glisten->type);
+ goto error;
}
if (video->driver)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6a9e109855..3630d687a6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -366,6 +366,8 @@ virDomainGraphicsDefFree;
virDomainGraphicsGetListen;
virDomainGraphicsListenAppendAddress;
virDomainGraphicsListenAppendSocket;
+virDomainGraphicsListenTypeFromString;
+virDomainGraphicsListenTypeToString;
virDomainGraphicsSpiceChannelModeTypeFromString;
virDomainGraphicsSpiceChannelModeTypeToString;
virDomainGraphicsSpiceChannelNameTypeFromString;
--
2.14.3