提交 a921699a 编写于 作者: J Ján Tomko

Use for instead of code duplication when parsing USB port

We are done if the string ends and move to another nesting
level if we find a dot.
上级 0956d9b2
......@@ -118,6 +118,8 @@ typedef struct _virDomainDeviceCcidAddress {
unsigned int slot;
} virDomainDeviceCcidAddress, *virDomainDeviceCcidAddressPtr;
# define VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH 4
typedef struct _virDomainDeviceUSBAddress {
unsigned int bus;
char *port;
......
......@@ -5104,17 +5104,20 @@ static int
virDomainDeviceUSBAddressParsePort(char *port)
{
unsigned int p;
char *tmp;
char *tmp = port;
size_t i;
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;
for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
if (virStrToLong_uip(tmp, &tmp, 10, &p) < 0)
break;
return 0;
if (*tmp == '\0')
return 0;
if (*tmp == '.')
tmp++;
}
error:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot parse <address> 'port' attribute"));
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册