mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
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.
This commit is contained in:
parent
0956d9b2a3
commit
a921699ad9
@ -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;
|
||||
|
||||
if (*tmp == '\0')
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (*tmp == '.')
|
||||
tmp++;
|
||||
}
|
||||
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot parse <address> 'port' attribute"));
|
||||
return -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user