]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: virDomainChrDefParseTargetXML refactor
authorKirill Shchetiniuk <kshcheti@redhat.com>
Tue, 22 Jul 2025 15:12:04 +0000 (17:12 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 23 Jul 2025 10:21:59 +0000 (12:21 +0200)
Refactored the default case port option parsing logic to use the
appropriate virXMLPropInt function.

Signed-off-by: Kirill Shchetiniuk <kshcheti@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c

index ba0d4a7b128c0aff1de2191f216142eec4543313..4f2045c21306443f4affdaee52221d6071103403 100644 (file)
@@ -10473,7 +10473,6 @@ virDomainChrDefParseTargetXML(virDomainChrDef *def,
     g_autofree char *targetType = virXMLPropString(cur, "type");
     g_autofree char *targetModel = NULL;
     g_autofree char *addrStr = NULL;
-    g_autofree char *portStr = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
     ctxt->node = cur;
@@ -10544,20 +10543,11 @@ virDomainChrDefParseTargetXML(virDomainChrDef *def,
         break;
 
     default:
-        portStr = virXMLPropString(cur, "port");
-        if (portStr == NULL) {
-            /* Set to negative value to indicate we should set it later */
-            def->target.port = -1;
-            break;
-        }
-
-        if (virStrToLong_ui(portStr, NULL, 10, &port) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid port number: %1$s"),
-                           portStr);
+        /* Set default to negative value to indicate we should set it later */
+        if (virXMLPropInt(cur, "port", 10,
+                          VIR_XML_PROP_NONNEGATIVE, &def->target.port, -1) < 0) {
             return -1;
         }
-        def->target.port = port;
         break;
     }