'index' is parsed to fit into a signed int but not have negative values.
virXMLPropInt can do that internally.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 14 +++-----------
.../pci-bridge-negative-index-invalid.err | 2 +-
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 77cb5f1456..70672c83ce 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8132,7 +8132,6 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
int ports;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
int rc;
- g_autofree char *idx = NULL;
g_autofree char *model = NULL;
ctxt->node = node;
@@ -8152,16 +8151,9 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
}
}
- idx = virXMLPropString(node, "index");
- if (idx) {
- unsigned int idxVal;
- if (virStrToLong_ui(idx, NULL, 10, &idxVal) < 0 || idxVal > INT_MAX) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Cannot parse controller index %s"), idx);
- return NULL;
- }
- def->idx = idxVal;
- }
+ if (virXMLPropInt(node, "index", 10, VIR_XML_PROP_NONNEGATIVE,
+ &def->idx, def->idx) < 0)
+ return NULL;
if ((driver = virXPathNode("./driver", ctxt))) {
if (virXMLPropUInt(driver, "queues", 10, VIR_XML_PROP_NONE,
diff --git a/tests/qemuxml2argvdata/pci-bridge-negative-index-invalid.err
b/tests/qemuxml2argvdata/pci-bridge-negative-index-invalid.err
index e258bcbee5..24a7d817e1 100644
--- a/tests/qemuxml2argvdata/pci-bridge-negative-index-invalid.err
+++ b/tests/qemuxml2argvdata/pci-bridge-negative-index-invalid.err
@@ -1 +1 @@
-internal error: Cannot parse controller index -1
+XML error: Invalid value for attribute 'index' in element 'controller':
'-1'. Expected non-negative value
--
2.37.1