[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol
From: |
Cao jin |
Subject: |
[Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol |
Date: |
Fri, 8 Jan 2016 16:37:50 +0800 |
strtol() don`t guarantee errno to be ERANGE on overflow.
This wrapper returns either -EINVAL or the errno set by strtol()
function (e.g -ERANGE).
Signed-off-by: Cao jin <address@hidden>
---
hw/xen/xen-host-pci-device.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
index 7d8a023..351b61a 100644
--- a/hw/xen/xen-host-pci-device.c
+++ b/hw/xen/xen-host-pci-device.c
@@ -148,7 +148,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;
rc = xen_host_pci_sysfs_path(d, name, path, sizeof (path));
if (rc) {
@@ -167,13 +167,8 @@ 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) {
*pvalue = value;
}
out:
--
2.1.0