[libvirt] [PATCH 2/5] conf: Return error when resolution values are invalid

Jonathon Jongsma jjongsma at redhat.com
Fri Oct 18 21:40:20 UTC 2019


Report an error and return NULL when either the 'x' or 'y' resolution
values cannot be converted to unsigned integers rather than returning
the incomplete 'def' variable. Switch 'def' to an autofree variable to
simplify the logic and remove the goto.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 src/conf/domain_conf.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 88e93f6fb8..5657faf039 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15349,7 +15349,7 @@ static virDomainVideoResolutionDefPtr
 virDomainVideoResolutionDefParseXML(xmlNodePtr node)
 {
     xmlNodePtr cur;
-    virDomainVideoResolutionDefPtr def;
+    g_autofree virDomainVideoResolutionDefPtr def = NULL;
     g_autofree char *x = NULL;
     g_autofree char *y = NULL;
 
@@ -15368,14 +15368,13 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node)
     if (!x || !y)
         return NULL;
 
-    if (VIR_ALLOC(def) < 0)
-        goto cleanup;
+    def = g_new0(virDomainVideoResolutionDef, 1);
 
     if (x) {
         if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("cannot parse video x-resolution '%s'"), x);
-            goto cleanup;
+            return NULL;
         }
     }
 
@@ -15383,12 +15382,11 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node)
         if (virStrToLong_uip(y, NULL, 10, &def->y) < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("cannot parse video y-resolution '%s'"), y);
-            goto cleanup;
+            return NULL;
         }
     }
 
- cleanup:
-    return def;
+    return g_steal_pointer(&def);
 }
 
 static virDomainVideoDriverDefPtr
-- 
2.21.0




More information about the libvir-list mailing list