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/conf/device_conf.c | 4 +-
src/conf/domain_addr.c | 10 +-
src/conf/domain_audit.c | 4 +
src/conf/domain_conf.c | 468 ++++++++++++++++++++++++++++++++-------
src/conf/domain_event.c | 1 +
src/conf/interface_conf.c | 21 +-
src/conf/netdev_bandwidth_conf.h | 4 +-
src/conf/network_conf.c | 8 +-
src/conf/network_event.c | 1 +
src/conf/node_device_conf.c | 27 ++-
src/conf/node_device_event.c | 1 +
src/conf/nwfilter_conf.c | 1 +
src/conf/nwfilter_params.c | 14 ++
src/conf/secret_event.c | 1 +
src/conf/storage_event.c | 1 +
src/conf/virnodedeviceobj.c | 1 +
src/conf/virstorageobj.c | 1 +
17 files changed, 468 insertions(+), 100 deletions(-)
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index d69f94fadf..6037d290e9 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -83,7 +83,6 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
switch ((virDomainDeviceAddressType) a->type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
- case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
/* address types below don't have any specific data */
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
@@ -140,6 +139,9 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
if (memcmp(&a->addr.dimm, &b->addr.dimm, sizeof(a->addr.dimm)))
return false;
break;
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+ default:
+ return false;
}
return true;
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index df19c6be1a..98230fc267 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -70,8 +70,10 @@ virDomainPCIControllerModelToConnectType(virDomainControllerModelPCI
model)
case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
return VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT;
+
+ default:
+ return 0;
}
- return 0;
}
@@ -352,6 +354,11 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus,
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("PCI controller model was not set
correctly"));
return -1;
+
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected PCI controller model %d"), model);
+ return -1;
}
bus->model = model;
@@ -1753,6 +1760,7 @@ virDomainUSBAddressControllerModelToPorts(virDomainControllerDefPtr
cont)
case VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT:
case VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE:
case VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST:
+ default:
break;
}
return 0;
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 82868bca76..f0a7ad7a48 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -191,6 +191,7 @@ virDomainAuditSmartcard(virDomainObjPtr vm,
break;
case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
+ default:
break;
}
}
@@ -236,6 +237,7 @@ virDomainAuditRNG(virDomainObjPtr vm,
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
+ default:
break;
}
}
@@ -251,6 +253,7 @@ virDomainAuditRNG(virDomainObjPtr vm,
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
+ default:
break;
}
}
@@ -1017,6 +1020,7 @@ virDomainAuditInput(virDomainObjPtr vm,
break;
case VIR_DOMAIN_INPUT_TYPE_LAST:
+ default:
break;
}
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 538dfc84bd..9cc6e87ccb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1038,7 +1038,10 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap,
break;
case VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected key cipher %d"), name_type);
+ goto cleanup;
}
ret = 0;
@@ -1411,6 +1414,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
break;
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
+ default:
break;
}
@@ -1429,12 +1433,13 @@ const char *virDomainInputDefGetPath(virDomainInputDefPtr input)
case VIR_DOMAIN_INPUT_TYPE_KBD:
case VIR_DOMAIN_INPUT_TYPE_LAST:
return NULL;
- break;
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
return input->source.evdev;
+
+ default:
+ return NULL;
}
- return NULL;
}
void virDomainInputDefFree(virDomainInputDefPtr def)
@@ -1919,6 +1924,7 @@ virDomainControllerDefNew(virDomainControllerType type)
case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
case VIR_DOMAIN_CONTROLLER_TYPE_LAST:
+ default:
break;
}
@@ -2075,6 +2081,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
case VIR_DOMAIN_NET_TYPE_ETHERNET:
case VIR_DOMAIN_NET_TYPE_USER:
case VIR_DOMAIN_NET_TYPE_LAST:
+ default:
break;
}
@@ -2137,6 +2144,7 @@ virDomainChrSourceDefGetPath(virDomainChrSourceDefPtr chr)
case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
case VIR_DOMAIN_CHR_TYPE_LAST:
+ default:
return NULL;
}
@@ -2179,6 +2187,9 @@ virDomainChrSourceDefClear(virDomainChrSourceDefPtr def)
case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
VIR_FREE(def->data.spiceport.channel);
break;
+
+ default:
+ break;
}
VIR_FREE(def->logfile);
@@ -2249,6 +2260,11 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
return -1;
break;
+
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev type %d"), src->type);
+ return -1;
}
dest->type = src->type;
@@ -2338,6 +2354,9 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef *src,
case VIR_DOMAIN_CHR_TYPE_STDIO:
case VIR_DOMAIN_CHR_TYPE_LAST:
break;
+
+ default:
+ return false;
}
return true;
@@ -2359,6 +2378,8 @@ void virDomainChrDefFree(virDomainChrDefPtr def)
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
VIR_FREE(def->target.name);
break;
+ default:
+ break;
}
break;
@@ -2564,6 +2585,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
virNetDevIPInfoClear(&def->source.caps.u.net.ip);
break;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
+ default:
break;
}
break;
@@ -2579,9 +2601,12 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+ default:
break;
}
break;
+ default:
+ break;
}
}
@@ -2595,6 +2620,7 @@ void virDomainTPMDefFree(virDomainTPMDefPtr def)
VIR_FREE(def->data.passthrough.source.data.file.path);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
+ default:
break;
}
@@ -2739,6 +2765,7 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
break;
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_NONE:
+ default:
break;
}
@@ -3552,9 +3579,10 @@ int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info,
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
return 1;
- }
- return 0;
+ default:
+ return 0;
+ }
}
virDomainDeviceInfoPtr
@@ -3608,6 +3636,7 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device)
case VIR_DOMAIN_DEVICE_IOMMU:
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_NONE:
+ default:
break;
}
return NULL;
@@ -3832,6 +3861,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
case VIR_DOMAIN_DEVICE_RNG:
case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_IOMMU:
+ default:
break;
}
#endif
@@ -4111,9 +4141,15 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def)
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
- case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
/* Nothing to do */
break;
+
+ case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev target type %d"),
+ def->serials[0]->targetType);
+ return -1;
}
}
@@ -4468,8 +4504,14 @@ virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
- case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
break;
+
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev subsys type %d"),
+ dev->source.subsys.type);
+ return -1;
}
return 0;
@@ -4893,6 +4935,7 @@ virDomainVcpuDefPostParse(virDomainDefPtr def)
case VIR_TRISTATE_BOOL_YES:
case VIR_TRISTATE_BOOL_LAST:
+ default:
break;
}
}
@@ -5171,12 +5214,12 @@ virDomainDiskAddressDiskBusCompatibility(virDomainDiskBus bus,
case VIR_DOMAIN_DISK_BUS_SD:
case VIR_DOMAIN_DISK_BUS_LAST:
return true;
+ default:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unexpected bus type '%d'"),
+ bus);
+ return false;
}
-
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unexpected bus type '%d'"),
- bus);
- return true;
}
@@ -5336,6 +5379,11 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def,
return -1;
}
break;
+
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev type %d"), def->type);
+ return -1;
}
return 0;
@@ -5480,8 +5528,13 @@ virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev)
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
- case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev subsys type %d"),
+ hostdev->source.subsys.type);
+ return -1;
}
}
return 0;
@@ -5547,8 +5600,12 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_IOMMU:
case VIR_DOMAIN_DEVICE_NONE:
- case VIR_DOMAIN_DEVICE_LAST:
break;
+ case VIR_DOMAIN_DEVICE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected device type %d"), dev->type);
+ return -1;
}
return 0;
@@ -5854,16 +5911,24 @@ virDomainDefLifecycleActionAllowed(virDomainLifecycle type,
case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART:
case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME:
case VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE:
- case VIR_DOMAIN_LIFECYCLE_ACTION_LAST:
return true;
case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY:
case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART:
break;
+ case VIR_DOMAIN_LIFECYCLE_ACTION_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected lifecycle action %d"), action);
+ return false;
}
break;
case VIR_DOMAIN_LIFECYCLE_CRASH:
- case VIR_DOMAIN_LIFECYCLE_LAST:
return true;
+ case VIR_DOMAIN_LIFECYCLE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected lifecycle type %d"), type);
+ return false;
}
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -6169,6 +6234,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+ default:
break;
}
@@ -6674,8 +6740,12 @@ virDomainDeviceAddressParseXML(xmlNodePtr address,
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
- case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
break;
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected device type %d"), info->type);
+ goto cleanup;
}
ret = 0;
@@ -7351,12 +7421,16 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode,
wwpn = NULL;
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE:
- case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_LAST:
virReportError(VIR_ERR_XML_ERROR,
_("Invalid hostdev protocol '%s'"),
virDomainHostdevSubsysSCSIHostProtocolTypeToString(hostsrc->protocol));
goto cleanup;
- break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev SCSI protocol %d"),
+ hostsrc->protocol);
+ goto cleanup;
}
ret = 0;
@@ -7560,10 +7634,11 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
goto error;
break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
default:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("address type='%s' not supported in hostdev
interfaces"),
- virDomainHostdevSubsysTypeToString(def->source.subsys.type));
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev susbys type %d"),
+ def->source.subsys.type);
goto error;
}
@@ -7827,10 +7902,11 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
ctxt, &def->source.caps.u.net.ip) < 0)
goto error;
break;
+ case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
default:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("address type='%s' not supported in hostdev
interfaces"),
- virDomainHostdevCapsTypeToString(def->source.caps.type));
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev caps type %d"),
+ def->source.caps.type);
goto error;
}
ret = 0;
@@ -7960,9 +8036,19 @@ virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt,
def->info.addr.drive.unit = idx % 2;
break;
- default:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
/* Other disk bus's aren't controller based */
break;
+ case VIR_DOMAIN_DISK_BUS_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected domain disk bus %d"),
+ def->bus);
+ return -1;
}
return 0;
@@ -8644,9 +8730,9 @@ virDomainDiskSourceParse(xmlNodePtr node,
break;
case VIR_STORAGE_TYPE_NONE:
case VIR_STORAGE_TYPE_LAST:
+ default:
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected disk type %s"),
- virStorageTypeToString(src->type));
+ _("Unexpected storage type %d"), src->type);
goto cleanup;
}
@@ -10159,6 +10245,8 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI3:
masterPort = 4;
break;
+ default:
+ break;
}
if (masterPort != -1 &&
def->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_NONE) {
@@ -10196,10 +10284,14 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS:
- case VIR_DOMAIN_CONTROLLER_MODEL_PCI_DEFAULT:
- case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
/* Other controller models don't require extra checks */
break;
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCI_DEFAULT:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected controller model %d"),
def->model);
+ goto error;
}
if (modelName &&
(def->opts.pciopts.modelName
@@ -11298,8 +11390,12 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
case VIR_DOMAIN_NET_TYPE_ETHERNET:
case VIR_DOMAIN_NET_TYPE_USER:
- case VIR_DOMAIN_NET_TYPE_LAST:
break;
+ case VIR_DOMAIN_NET_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected net type %d"), def->type);
+ goto error;
}
if (virDomainNetIPInfoParseXML(_("guest interface"),
@@ -11670,9 +11766,13 @@ virDomainChrDefaultTargetType(int devtype)
return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
- case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
/* No target type yet*/
break;
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev device type %d"), devtype);
+ return -1;
}
return 0;
@@ -11701,10 +11801,14 @@ virDomainChrTargetTypeFromString(int devtype,
break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
- case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
/* No target type yet*/
ret = 0;
break;
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev device type %d"), devtype);
+ break;
}
return ret;
@@ -11727,10 +11831,14 @@ virDomainChrTargetModelFromString(int devtype,
case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
- case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
/* Target model not supported yet */
ret = 0;
break;
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev device type %d"), devtype);
+ break;
}
return ret;
@@ -11777,9 +11885,9 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
goto error;
}
- switch (def->deviceType) {
+ switch ((virDomainChrDeviceType)def->deviceType) {
case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
- switch (def->targetType) {
+ switch ((virDomainChrChannelTargetType)def->targetType) {
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
addrStr = virXMLPropString(cur, "address");
portStr = virXMLPropString(cur, "port");
@@ -11840,10 +11948,22 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
def->state = tmp;
}
break;
+
+ case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE:
+ break;
+
+ case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected channel target type %d"),
+ def->targetType);
+ goto error;
}
break;
- default:
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
portStr = virXMLPropString(cur, "port");
if (portStr == NULL) {
/* Set to negative value to indicate we should set it later */
@@ -11859,6 +11979,13 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
}
def->target.port = port;
break;
+
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev device type %d"),
+ def->deviceType);
+ goto error;
}
@@ -12153,12 +12280,17 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
def->data.nmdm.slave = virXMLPropString(cur, "slave");
break;
- 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:
break;
+
+ case VIR_DOMAIN_CHR_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev type %d"), def->type);
+ goto error;
}
/* Check for an optional seclabel override in <source/>. */
@@ -12594,6 +12726,9 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt,
path = NULL;
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected TPM type %d"), def->type);
goto error;
}
@@ -13117,8 +13252,13 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr
def,
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
- case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected graphics listen type %d"),
+ graphics->type);
+ goto error;
}
if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
@@ -13859,7 +13999,11 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
goto error;
break;
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected graphics type %d"),
+ def->type);
+ goto error;
}
cleanup:
@@ -14119,7 +14263,11 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt,
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected RNG backend %d"),
+ def->backend);
+ goto error;
}
if (virDomainDeviceInfoParseXML(xmlopt, node, NULL, &def->info, flags) <
0)
@@ -15004,8 +15152,13 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
- case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev subsystem type %d"),
+ def->source.subsys.type);
+ goto error;
}
}
@@ -15421,8 +15574,13 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
break;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
- case VIR_DOMAIN_MEMORY_MODEL_LAST:
break;
+ case VIR_DOMAIN_MEMORY_MODEL_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected memory model %d"),
+ def->model);
+ goto cleanup;
}
ret = 0;
@@ -15788,7 +15946,10 @@ virDomainDeviceDefParse(const char *xmlStr,
break;
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected device type %d"), dev->type);
+ goto error;
}
/* callback to fill driver specific device aspects */
@@ -16006,9 +16167,9 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
return virDomainHostdevMatchSubsysMediatedDev(a, b);
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+ default:
return 0;
}
- return 0;
}
@@ -16045,15 +16206,17 @@ virDomainHostdevMatchCaps(virDomainHostdevDefPtr a,
if (a->source.caps.type != b->source.caps.type)
return 0;
- switch (a->source.caps.type) {
+ switch ((virDomainHostdevCapsType)a->source.caps.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
return virDomainHostdevMatchCapsStorage(a, b);
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
return virDomainHostdevMatchCapsMisc(a, b);
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
return virDomainHostdevMatchCapsNet(a, b);
+ case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
+ default:
+ return 0;
}
- return 0;
}
@@ -16064,13 +16227,15 @@ virDomainHostdevMatch(virDomainHostdevDefPtr a,
if (a->mode != b->mode)
return 0;
- switch (a->mode) {
+ switch ((virDomainHostdevMode)a->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
return virDomainHostdevMatchSubsys(a, b);
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
return virDomainHostdevMatchCaps(a, b);
+ case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+ default:
+ return 0;
}
- return 0;
}
/* Find an entry in hostdevs that matches the source spec in
@@ -16695,11 +16860,14 @@ virDomainChrEquals(virDomainChrDefPtr src,
break;
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE:
+ return true;
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST:
- /* shouldn't happen */
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected channel target type %d"),
+ src->targetType);
+ return false;
}
- break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
if (src->targetType != tgt->targetType)
@@ -16710,12 +16878,13 @@ virDomainChrEquals(virDomainChrDefPtr src,
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
return src->target.port == tgt->target.port;
- break;
+
case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
- /* shouldn't happen */
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev device type %d"),
src->deviceType);
+ return false;
}
- return false;
}
virDomainChrDefPtr
@@ -16768,12 +16937,11 @@ virDomainChrGetDomainPtrsInternal(virDomainDefPtr vmdef,
return 0;
case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev type %d"), type);
+ return -1;
}
-
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unknown char device type: %d"), type);
- return -1;
}
@@ -16882,7 +17050,11 @@ virDomainRNGFind(virDomainDefPtr def,
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected RNG backend %d"),
+ rng->backend);
+ return -1;
}
if (rng->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
@@ -16958,8 +17130,12 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr def,
break;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
- case VIR_DOMAIN_MEMORY_MODEL_LAST:
break;
+ case VIR_DOMAIN_MEMORY_MODEL_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected memory model %d"), mem->model);
+ return -1;
}
break;
@@ -19284,6 +19460,7 @@ virDomainDefParseXML(xmlDocPtr xml,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_FEATURE_LAST:
+ default:
break;
}
}
@@ -19384,6 +19561,7 @@ virDomainDefParseXML(xmlDocPtr xml,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_HYPERV_LAST:
+ default:
break;
}
}
@@ -19430,6 +19608,7 @@ virDomainDefParseXML(xmlDocPtr xml,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_KVM_LAST:
+ default:
break;
}
}
@@ -19512,7 +19691,7 @@ virDomainDefParseXML(xmlDocPtr xml,
}
VIR_FREE(tmp);
- switch (def->clock.offset) {
+ switch ((virDomainClockOffsetType)def->clock.offset) {
case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME:
case VIR_DOMAIN_CLOCK_OFFSET_UTC:
tmp = virXPathString("string(./clock/@adjustment)", ctxt);
@@ -19534,6 +19713,8 @@ virDomainDefParseXML(xmlDocPtr xml,
case VIR_DOMAIN_CLOCK_OFFSET_UTC:
def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_UTC;
break;
+ default:
+ break;
}
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE;
}
@@ -19571,6 +19752,11 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
}
break;
+
+ case VIR_DOMAIN_CLOCK_OFFSET_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected clock offset %d"), def->clock.offset);
}
if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0)
@@ -20664,8 +20850,12 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
- case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
break;
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected device address type %d"), src->type);
+ return false;
}
return true;
@@ -21104,7 +21294,7 @@ virDomainChannelDefCheckABIStability(virDomainChrDefPtr src,
return false;
}
- switch (src->targetType) {
+ switch ((virDomainChrChannelTargetType)src->targetType) {
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN:
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
@@ -21137,6 +21327,15 @@ virDomainChannelDefCheckABIStability(virDomainChrDefPtr src,
return false;
}
break;
+
+ case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE:
+ break;
+
+ case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected channel target type %d"),
src->targetType);
+ return false;
}
if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
@@ -21283,7 +21482,10 @@ virDomainRedirdevDefCheckABIStability(virDomainRedirdevDefPtr
src,
}
break;
case VIR_DOMAIN_REDIRDEV_BUS_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected redirdev bus type %d"), src->bus);
+ return false;
}
if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
@@ -21433,6 +21635,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDefPtr src,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_HYPERV_LAST:
+ default:
break;
}
}
@@ -21457,6 +21660,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDefPtr src,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_KVM_LAST:
+ default:
break;
}
}
@@ -22188,6 +22392,7 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src,
case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_IOMMU:
+ default:
break;
}
#endif
@@ -22819,6 +23024,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
case VIR_STORAGE_TYPE_NONE:
case VIR_STORAGE_TYPE_LAST:
+ default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected disk type %d"), src->type);
goto error;
@@ -23438,7 +23644,7 @@ virDomainFSDefFormat(virBufferPtr buf,
virBufferAddLit(buf, "/>\n");
}
- switch (def->type) {
+ switch ((virDomainFSType)def->type) {
case VIR_DOMAIN_FS_TYPE_MOUNT:
case VIR_DOMAIN_FS_TYPE_BIND:
virBufferEscapeString(buf, "<source dir='%s'/>\n",
@@ -23471,6 +23677,12 @@ virDomainFSDefFormat(virBufferPtr buf,
virBufferEscapeString(buf, " volume='%s'",
def->src->srcpool->volume);
virBufferAddLit(buf, "/>\n");
break;
+
+ case VIR_DOMAIN_FS_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected filesystem type %d"), def->type);
+ return -1;
}
virBufferEscapeString(buf, "<target dir='%s'/>\n",
@@ -24138,8 +24350,12 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_NET_TYPE_USER:
- case VIR_DOMAIN_NET_TYPE_LAST:
break;
+ case VIR_DOMAIN_NET_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected net type %d"), def->type);
+ return -1;
}
/* if sourceLines == 0 - no <source> info at all so far
@@ -24323,7 +24539,6 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
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;
@@ -24416,6 +24631,11 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
def->data.spiceport.channel);
break;
+ case VIR_DOMAIN_CHR_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected chardev type %d"), def->type);
+ goto error;
}
if (def->logfile) {
@@ -24484,6 +24704,12 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
virDomainChrDeviceStateTypeToString(def->state));
}
break;
+
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected channel target type %d"),
+ def->targetType);
+ return -1;
}
virBufferAddLit(buf, "/>\n");
@@ -24543,6 +24769,7 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+ default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected char device type %d"),
def->deviceType);
@@ -24695,6 +24922,9 @@ virDomainTPMDefFormat(virBufferPtr buf,
def->data.passthrough.source.data.file.path);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected TPM type %d"), def->type);
break;
}
@@ -24963,9 +25193,14 @@ virDomainRNGDefFormat(virBufferPtr buf,
return -1;
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</backend>\n");
+ break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected RNG backend type %d"), def->backend);
+ virBufferFreeAndReset(&driverBuf);
+ return -1;
}
virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
@@ -24999,6 +25234,7 @@ virDomainRNGDefFree(virDomainRNGDefPtr def)
virDomainChrSourceDefFree(def->source.chardev);
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
+ default:
break;
}
@@ -25040,8 +25276,12 @@ virDomainMemorySourceDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
- case VIR_DOMAIN_MEMORY_MODEL_LAST:
break;
+ case VIR_DOMAIN_MEMORY_MODEL_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected memory model %d"), def->model);
+ goto cleanup;
}
virBufferAdjustIndent(buf, -2);
@@ -25494,8 +25734,12 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
virDomainGraphicsListenDefFormatAddr(buf, glisten, flags);
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
- case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected graphics listen type %d"),
glisten->type);
+ return -1;
}
if (def->data.vnc.keymap)
@@ -25596,7 +25840,10 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected graphics listen type %d"),
glisten->type);
+ return -1;
}
if (def->data.spice.keymap)
@@ -25611,7 +25858,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
- break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected graphics type %d"),
+ def->type);
+ return -1;
}
for (i = 0; i < def->nListens; i++) {
@@ -25777,7 +26028,7 @@ virDomainHostdevDefFormat(virBufferPtr buf,
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
- switch (def->mode) {
+ switch ((virDomainHostdevMode)def->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
if (virDomainHostdevDefFormatSubsys(buf, def, flags, false) < 0)
return -1;
@@ -25786,6 +26037,11 @@ virDomainHostdevDefFormat(virBufferPtr buf,
if (virDomainHostdevDefFormatCaps(buf, def) < 0)
return -1;
break;
+ case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected hostdev mode %d"), def->mode);
+ return -1;
}
if (def->readonly)
@@ -26074,6 +26330,7 @@ virDomainSchedulerFormat(virBufferPtr buf,
case VIR_PROC_POLICY_NONE:
case VIR_PROC_POLICY_LAST:
+ default:
break;
}
@@ -26775,6 +27032,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
case VIR_TRISTATE_SWITCH_LAST:
case VIR_TRISTATE_SWITCH_OFF:
+ default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected state of feature '%s'"),
name);
@@ -26790,6 +27048,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
case VIR_DOMAIN_FEATURE_VMPORT:
case VIR_DOMAIN_FEATURE_SMM:
switch ((virTristateSwitch) def->features[i]) {
+ default:
case VIR_TRISTATE_SWITCH_LAST:
case VIR_TRISTATE_SWITCH_ABSENT:
break;
@@ -26857,6 +27116,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_HYPERV_LAST:
+ default:
break;
}
@@ -26884,6 +27144,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_KVM_LAST:
+ default:
break;
}
}
@@ -26937,6 +27198,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_FEATURE_LAST:
+ default:
break;
}
}
@@ -26950,7 +27212,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAsprintf(buf, "<clock offset='%s'",
virDomainClockOffsetTypeToString(def->clock.offset));
- switch (def->clock.offset) {
+ switch ((virDomainClockOffsetType)def->clock.offset) {
case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME:
case VIR_DOMAIN_CLOCK_OFFSET_UTC:
if (def->clock.data.utc_reset)
@@ -26969,6 +27231,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE:
virBufferEscapeString(buf, " timezone='%s'",
def->clock.data.timezone);
break;
+ case VIR_DOMAIN_CLOCK_OFFSET_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected clock offset type %d"),
def->clock.offset);
+ goto error;
}
if (def->clock.ntimers == 0) {
virBufferAddLit(buf, "/>\n");
@@ -27871,10 +28138,10 @@ virDomainStateReasonToString(virDomainState state, int reason)
case VIR_DOMAIN_PMSUSPENDED:
return virDomainPMSuspendedReasonTypeToString(reason);
case VIR_DOMAIN_LAST:
- break;
+ default:
+ VIR_WARN("Unexpected domain state: %d", state);
+ return NULL;
}
- VIR_WARN("Unexpected domain state: %d", state);
- return NULL;
}
@@ -27899,10 +28166,10 @@ virDomainStateReasonFromString(virDomainState state, const char
*reason)
case VIR_DOMAIN_PMSUSPENDED:
return virDomainPMSuspendedReasonTypeFromString(reason);
case VIR_DOMAIN_LAST:
- break;
+ default:
+ VIR_WARN("Unexpected domain state: %d", state);
+ return -1;
}
- VIR_WARN("Unexpected domain state: %d", state);
- return -1;
}
@@ -28270,10 +28537,15 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
case VIR_DOMAIN_DEVICE_IOMMU:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Copying definition of '%s' type "
+ "is not implemented yet."),
+ virDomainDeviceTypeToString(src->type));
+ goto cleanup;
case VIR_DOMAIN_DEVICE_LAST:
+ default:
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Copying definition of '%d' type "
- "is not implemented yet."),
+ _("Unexpected device type %d"),
src->type);
goto cleanup;
}
@@ -28417,6 +28689,10 @@ virDomainObjGetMetadata(virDomainObjPtr vm,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_METADATA_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected metadata type %d"),
+ type);
break;
}
@@ -28503,6 +28779,10 @@ virDomainDefSetMetadata(virDomainDefPtr def,
/* coverity[dead_error_begin] */
case VIR_DOMAIN_METADATA_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected metadata type %d"),
+ type);
break;
}
@@ -28849,6 +29129,7 @@ virDomainNetTypeSharesHostView(const virDomainNetDef *net)
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
case VIR_DOMAIN_NET_TYPE_UDP:
case VIR_DOMAIN_NET_TYPE_LAST:
+ default:
break;
}
return false;
@@ -29141,6 +29422,11 @@ virDomainDiskTranslateSourcePool(virConnectPtr conn,
virStorageVolTypeToString(info.type),
virStoragePoolTypeToString(pooldef->type));
goto cleanup;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected storage vol type %d"),
+ info.type);
+ goto cleanup;
}
break;
@@ -29185,6 +29471,11 @@ virDomainDiskTranslateSourcePool(virConnectPtr conn,
if (virDomainDiskAddISCSIPoolSourceHost(def, pooldef) < 0)
goto cleanup;
break;
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected storage pool mode %d"),
+ def->src->srcpool->mode);
+ goto cleanup;
}
break;
@@ -29192,12 +29483,17 @@ virDomainDiskTranslateSourcePool(virConnectPtr conn,
case VIR_STORAGE_POOL_RBD:
case VIR_STORAGE_POOL_SHEEPDOG:
case VIR_STORAGE_POOL_GLUSTER:
- case VIR_STORAGE_POOL_LAST:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("using '%s' pools for backing 'volume'
disks "
"isn't yet supported"),
virStoragePoolTypeToString(pooldef->type));
goto cleanup;
+ case VIR_STORAGE_POOL_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected storage pool type %d"),
+ pooldef->type);
+ goto cleanup;
}
ret = 0;
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 7baccd5b57..a6202ec1b1 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -2042,6 +2042,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
goto cleanup;
}
case VIR_DOMAIN_EVENT_ID_LAST:
+ default:
break;
}
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 0a4b28f489..89f77a719e 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -83,7 +83,7 @@ virInterfaceDefFree(virInterfaceDefPtr def)
VIR_FREE(def->name);
VIR_FREE(def->mac);
- switch (def->type) {
+ switch ((virInterfaceType)def->type) {
case VIR_INTERFACE_TYPE_BRIDGE:
VIR_FREE(def->data.bridge.delay);
for (i = 0; i < def->data.bridge.nbItf; i++) {
@@ -106,6 +106,10 @@ virInterfaceDefFree(virInterfaceDefPtr def)
VIR_FREE(def->data.vlan.tag);
VIR_FREE(def->data.vlan.dev_name);
break;
+ case VIR_INTERFACE_TYPE_ETHERNET:
+ case VIR_INTERFACE_TYPE_LAST:
+ default:
+ break;
}
/* free all protos */
@@ -760,7 +764,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
goto error;
}
- switch (type) {
+ switch ((virInterfaceType)type) {
case VIR_INTERFACE_TYPE_ETHERNET:
if ((tmp = virXPathString("string(./mac/@address)", ctxt)))
def->mac = tmp;
@@ -804,7 +808,11 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
goto error;
break;
}
-
+ case VIR_INTERFACE_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected interface type %d"), type);
+ goto error;
}
ctxt->node = cur;
@@ -1115,7 +1123,7 @@ virInterfaceDefDevFormat(virBufferPtr buf,
if (def->type != VIR_INTERFACE_TYPE_BRIDGE)
virInterfaceLinkFormat(buf, &def->lnk);
- switch (def->type) {
+ switch ((virInterfaceType)def->type) {
case VIR_INTERFACE_TYPE_ETHERNET:
if (def->mac)
virBufferAsprintf(buf, "<mac address='%s'/>\n",
def->mac);
@@ -1129,6 +1137,11 @@ virInterfaceDefDevFormat(virBufferPtr buf,
case VIR_INTERFACE_TYPE_VLAN:
virInterfaceVlanDefFormat(buf, def);
break;
+ case VIR_INTERFACE_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected interface type %d"), def->type);
+ goto cleanup;
}
virBufferAdjustIndent(buf, -2);
diff --git a/src/conf/netdev_bandwidth_conf.h b/src/conf/netdev_bandwidth_conf.h
index 30f988953c..3d2ebb62b4 100644
--- a/src/conf/netdev_bandwidth_conf.h
+++ b/src/conf/netdev_bandwidth_conf.h
@@ -56,9 +56,9 @@ static inline bool virNetDevSupportBandwidth(virDomainNetType type)
case VIR_DOMAIN_NET_TYPE_INTERNAL:
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
case VIR_DOMAIN_NET_TYPE_LAST:
- break;
+ default:
+ return false;
}
- return false;
}
#endif /* __VIR_NETDEV_BANDWIDTH_CONF_H__ */
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 54109a3d2e..e91df37463 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1874,7 +1874,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
/* Validate some items in the main NetworkDef that need to align
* with the chosen forward mode.
*/
- switch (def->forward.type) {
+ switch ((virNetworkForwardType)def->forward.type) {
case VIR_NETWORK_FORWARD_NONE:
break;
@@ -1955,6 +1955,12 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
}
break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected forward type %d"), def->forward.type);
+ goto error;
}
VIR_FREE(stp);
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index e0d1a3d5ca..d005784b52 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -114,6 +114,7 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn,
}
case VIR_NETWORK_EVENT_ID_LAST:
+ default:
break;
}
VIR_WARN("Unexpected event ID %d", event->eventID);
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index fd8f4e4a94..5dd945a07f 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -592,8 +592,14 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
case VIR_NODE_DEV_CAP_MDEV_TYPES:
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
- case VIR_NODE_DEV_CAP_LAST:
break;
+ case VIR_NODE_DEV_CAP_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected node device capability %d"),
+ caps->data.type);
+ virBufferFreeAndReset(&buf);
+ return NULL;
}
virBufferAdjustIndent(&buf, -2);
@@ -1884,12 +1890,16 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
case VIR_NODE_DEV_CAP_SCSI_GENERIC:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid capability type '%s' for
'%s'"),
+ virNodeDevCapTypeToString(caps->data.type), def->name);
+ goto error;
case VIR_NODE_DEV_CAP_LAST:
+ default:
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown capability type '%d' for
'%s'"),
+ _("Unexpected node device capability '%d' for
'%s'"),
caps->data.type, def->name);
- ret = -1;
- break;
+ goto error;
}
if (ret < 0)
@@ -1967,6 +1977,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
def->devlinks[m++] = (char*)xmlNodeGetContent(node);
break;
case VIR_NODE_DEV_DEVNODE_LAST:
+ default:
break;
}
}
@@ -2213,6 +2224,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
case VIR_NODE_DEV_CAP_VPORTS:
case VIR_NODE_DEV_CAP_CCW_DEV:
case VIR_NODE_DEV_CAP_LAST:
+ default:
/* This case is here to shutup the compiler */
break;
}
@@ -2464,8 +2476,13 @@ virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def)
case VIR_NODE_DEV_CAP_MDEV_TYPES:
case VIR_NODE_DEV_CAP_MDEV:
case VIR_NODE_DEV_CAP_CCW_DEV:
- case VIR_NODE_DEV_CAP_LAST:
break;
+ case VIR_NODE_DEV_CAP_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unexpected node device capability %d"),
+ cap->data.type);
+ return -1;
}
cap = cap->next;
}
diff --git a/src/conf/node_device_event.c b/src/conf/node_device_event.c
index 312ef512d1..3b1e059b2c 100644
--- a/src/conf/node_device_event.c
+++ b/src/conf/node_device_event.c
@@ -146,6 +146,7 @@ virNodeDeviceEventDispatchDefaultFunc(virConnectPtr conn,
}
case VIR_NODE_DEVICE_EVENT_ID_LAST:
+ default:
break;
}
VIR_WARN("Unexpected event ID %d", event->eventID);
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 9e8c725f9f..56f2800ea7 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2398,6 +2398,7 @@ virNWFilterRuleDefFixup(virNWFilterRuleDefPtr rule)
break;
case VIR_NWFILTER_RULE_PROTOCOL_LAST:
+ default:
break;
}
#undef COPY_NEG_SIGN
diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c
index 3a01049182..586fa539d2 100644
--- a/src/conf/nwfilter_params.c
+++ b/src/conf/nwfilter_params.c
@@ -60,6 +60,7 @@ virNWFilterVarValueFree(virNWFilterVarValuePtr val)
VIR_FREE(val->u.array.values);
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
break;
}
VIR_FREE(val);
@@ -92,6 +93,7 @@ virNWFilterVarValueCopy(const virNWFilterVarValue *val)
}
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
break;
}
@@ -162,6 +164,7 @@ virNWFilterVarValueGetNthValue(const virNWFilterVarValue* val,
unsigned int idx)
res = val->u.array.values[idx];
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
break;
}
@@ -179,6 +182,7 @@ virNWFilterVarValueGetCardinality(const virNWFilterVarValue *val)
return val->u.array.nValues;
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
return 0;
}
return 0;
@@ -246,6 +250,7 @@ virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value)
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
break;
}
@@ -283,6 +288,7 @@ virNWFilterVarValueDelNthValue(virNWFilterVarValuePtr val, unsigned
int pos)
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
break;
}
@@ -305,6 +311,7 @@ virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char
*value)
break;
case NWFILTER_VALUE_TYPE_LAST:
+ default:
break;
}
@@ -373,6 +380,7 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie,
minValue = 0;
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
return -1;
}
@@ -514,6 +522,7 @@ virNWFilterVarCombIterCreate(virNWFilterHashTablePtr hash,
res->nIter++;
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
goto err_exit;
}
@@ -587,6 +596,7 @@ virNWFilterVarCombIterGetVarValue(virNWFilterVarCombIterPtr ci,
}
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
return NULL;
}
@@ -940,6 +950,7 @@ virNWFilterVarAccessEqual(const virNWFilterVarAccess *a,
return a->u.iterId == b->u.iterId;
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
break;
}
return false;
@@ -1025,6 +1036,7 @@ virNWFilterVarAccessParse(const char *varAccess)
dest->u.iterId = result;
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
goto err_exit;
}
@@ -1053,6 +1065,7 @@ virNWFilterVarAccessPrint(virNWFilterVarAccessPtr vap, virBufferPtr
buf)
virBufferAsprintf(buf, "[@%u]", vap->u.iterId);
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
break;
}
}
@@ -1117,6 +1130,7 @@ virNWFilterVarAccessIsAvailable(const virNWFilterVarAccess
*varAccess,
case VIR_NWFILTER_VAR_ACCESS_ITERATOR:
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
+ default:
return false;
}
diff --git a/src/conf/secret_event.c b/src/conf/secret_event.c
index c130909282..ce5767a49a 100644
--- a/src/conf/secret_event.c
+++ b/src/conf/secret_event.c
@@ -147,6 +147,7 @@ virSecretEventDispatchDefaultFunc(virConnectPtr conn,
}
case VIR_SECRET_EVENT_ID_LAST:
+ default:
break;
}
VIR_WARN("Unexpected event ID %d", event->eventID);
diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c
index f9b796878a..2f37adb875 100644
--- a/src/conf/storage_event.c
+++ b/src/conf/storage_event.c
@@ -147,6 +147,7 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
}
case VIR_STORAGE_POOL_EVENT_ID_LAST:
+ default:
break;
}
VIR_WARN("Unexpected event ID %d", event->eventID);
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index ad0f27ee47..82c84b37fe 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -680,6 +680,7 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
case VIR_NODE_DEV_CAP_MDEV:
case VIR_NODE_DEV_CAP_CCW_DEV:
case VIR_NODE_DEV_CAP_LAST:
+ default:
break;
}
}
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 799b8c9fa3..e6c5704989 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1880,6 +1880,7 @@ virStoragePoolObjSourceFindDuplicateCb(const void *payload,
case VIR_STORAGE_POOL_RBD:
case VIR_STORAGE_POOL_LAST:
+ default:
break;
}
--
2.14.3