mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
conf: Improve metadata type verification
Split out checking of invalid metadata type from the switch statement so that we can use the typecasted enum value to allow tracking addition of new items by the compliler. Also avoids two dead-code break statements.
This commit is contained in:
parent
e871ab8862
commit
3738166603
@ -19575,6 +19575,12 @@ virDomainObjGetMetadata(virDomainObjPtr vm,
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, NULL);
|
||||
|
||||
if (type >= VIR_DOMAIN_METADATA_LAST) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("unknown metadata type '%d'"), type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virDomainLiveConfigHelperMethod(caps, xmlopt, vm, &flags, &def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -19601,10 +19607,7 @@ virDomainObjGetMetadata(virDomainObjPtr vm,
|
||||
goto cleanup;
|
||||
break;
|
||||
|
||||
default:
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("unknown metadata type"));
|
||||
goto cleanup;
|
||||
case VIR_DOMAIN_METADATA_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -19630,6 +19633,12 @@ virDomainDefSetMetadata(virDomainDefPtr def,
|
||||
char *tmp;
|
||||
int ret = -1;
|
||||
|
||||
if (type >= VIR_DOMAIN_METADATA_LAST) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("unknown metadata type '%d'"), type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
switch ((virDomainMetadataType) type) {
|
||||
case VIR_DOMAIN_METADATA_DESCRIPTION:
|
||||
if (VIR_STRDUP(tmp, metadata) < 0)
|
||||
@ -19683,10 +19692,7 @@ virDomainDefSetMetadata(virDomainDefPtr def,
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("unknown metadata type"));
|
||||
goto cleanup;
|
||||
case VIR_DOMAIN_METADATA_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user