Make rewriting it easier.
---
src/conf/domain_conf.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 69995cc..bcf832d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5062,11 +5062,30 @@ virDomainDeviceCcidAddressParseXML(xmlNodePtr node,
}
static int
+virDomainDeviceUSBAddressParsePort(char *port)
+{
+ unsigned int p;
+ char *tmp;
+
+ if ((virStrToLong_uip(port, &tmp, 10, &p) < 0 || (*tmp != '\0'
&& *tmp != '.')) ||
+ (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p)
< 0 || (*tmp != '\0' && *tmp != '.'))) ||
+ (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p)
< 0 || (*tmp != '\0' && *tmp != '.'))) ||
+ (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p)
< 0 || (*tmp != '\0'))))
+ goto error;
+
+ return 0;
+
+ error:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Cannot parse <address> 'port'
attribute"));
+ return -1;
+}
+
+static int
virDomainDeviceUSBAddressParseXML(xmlNodePtr node,
virDomainDeviceUSBAddressPtr addr)
{
- char *port, *bus, *tmp;
- unsigned int p;
+ char *port, *bus;
int ret = -1;
memset(addr, 0, sizeof(*addr));
@@ -5074,15 +5093,8 @@ virDomainDeviceUSBAddressParseXML(xmlNodePtr node,
port = virXMLPropString(node, "port");
bus = virXMLPropString(node, "bus");
- if (port &&
- ((virStrToLong_uip(port, &tmp, 10, &p) < 0 || (*tmp != '\0'
&& *tmp != '.')) ||
- (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p)
< 0 || (*tmp != '\0' && *tmp != '.'))) ||
- (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p)
< 0 || (*tmp != '\0' && *tmp != '.'))) ||
- (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p)
< 0 || (*tmp != '\0'))))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Cannot parse <address> 'port'
attribute"));
+ if (port && virDomainDeviceUSBAddressParsePort(port) < 0)
goto cleanup;
- }
addr->port = port;
port = NULL;
--
2.7.3