[PATCHv2] conf: Improve metadata type verification

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

 



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.
---
Version 2:
- move the check back to the original function so that we don't break forward compat

 src/conf/domain_conf.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b80e7cf..fa76eb4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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;
     }

-- 
2.0.0

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