On 01/08/2016 01:37 AM, Cao jin wrote:
strtol() don`t guarantee errno to be ERANGE on overflow.
I stand slightly corrected: C99 requires ERANGE on overflow, but not
EINVAL; it is POSIX that adds EINVAL, but does not properly require it.
At any rate, my main point was that errno is not always properly set by
all strtol implementations, and furthermore that you can't rely on it
being set to a sane value if you didn't pre-set it to 0.
Signed-off-by: Cao jin <address@hidden>
---
hw/xen/xen-host-pci-device.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
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);
Why did you switch from strtol() to qemu_strtoul()? Was signed parsing
incorrect, and unsigned parsing a bug fix? If so, please mention it in
the commit message as intentional. Otherwise, use qemu_strtol() (and
adjust the commit message accordingly).