From: Cao jin Date: Sun, 17 Jan 2016 12:13:11 +0000 (+0800) Subject: Xen: use qemu_strtoul instead of strtol X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f524bc3b3da5bd595840fca93d43a9852b8d066f;p=people%2Fliuw%2Flibxenctrl-split%2Fqemu-xen.git Xen: use qemu_strtoul instead of strtol No need to roll our own (with slightly incorrect handling of errno), when we can use the common version. Change signed parsing to unsigned, because what it read are values in PCI config space, which are non-negative. Signed-off-by: Cao jin Reviewed-by: Stefano Stabellini Reviewed-by: Eric Blake --- diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c index 9c342e758..83da9c47c 100644 --- a/hw/xen/xen-host-pci-device.c +++ b/hw/xen/xen-host-pci-device.c @@ -141,7 +141,7 @@ static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name, char buf[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE]; int fd, rc; unsigned long value; - char *endptr; + const char *endptr; xen_host_pci_sysfs_path(d, name, path, sizeof(path)); @@ -158,13 +158,9 @@ static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name, } } while (rc < 0); buf[rc] = 0; - value = strtol(buf, &endptr, base); - if (endptr == buf || *endptr != '\n') { - rc = -1; - } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) { - rc = -errno; - } else { - rc = 0; + rc = qemu_strtoul(buf, &endptr, base, &value); + if (!rc) { + assert(value <= UINT_MAX); *pvalue = value; } out: