summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorpluknet <pluknet@FreeBSD.org>2013-08-21 22:37:15 +0000
committerpluknet <pluknet@FreeBSD.org>2013-08-21 22:37:15 +0000
commit96dfe577d25fd7efedf4ae97d4a81f81ae7fd1c8 (patch)
tree46aa7220e77a111bb6f8179411f69c0dc730fc4d /lib
parentf3b717cec9765ebd1d6b042e35b047f3a49929d4 (diff)
downloadFreeBSD-src-96dfe577d25fd7efedf4ae97d4a81f81ae7fd1c8.zip
FreeBSD-src-96dfe577d25fd7efedf4ae97d4a81f81ae7fd1c8.tar.gz
Reset errno before strtoumax() call to properly detect ERANGE.
Restore saved errno if strtoumax() call is successful. Reported by: ache Reviewed by: jilles MFC after: 1 week
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/expand_number.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/libutil/expand_number.c b/lib/libutil/expand_number.c
index 0a62c12..401e2d9 100644
--- a/lib/libutil/expand_number.c
+++ b/lib/libutil/expand_number.c
@@ -50,15 +50,22 @@ int
expand_number(const char *buf, uint64_t *num)
{
uint64_t number;
+ int saved_errno;
unsigned shift;
char *endptr;
+ saved_errno = errno;
+ errno = 0;
+
number = strtoumax(buf, &endptr, 0);
if (number == UINTMAX_MAX && errno == ERANGE) {
return (-1);
}
+ if (errno == 0)
+ errno = saved_errno;
+
if (endptr == buf) {
/* No valid digits. */
errno = EINVAL;
OpenPOWER on IntegriCloud