svn commit: r254621 - head/lib/libutil
Sergey Kandaurov
pluknet at FreeBSD.org
Wed Aug 21 22:37:16 UTC 2013
Author: pluknet
Date: Wed Aug 21 22:37:15 2013
New Revision: 254621
URL: http://svnweb.freebsd.org/changeset/base/254621
Log:
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
Modified:
head/lib/libutil/expand_number.c
Modified: head/lib/libutil/expand_number.c
==============================================================================
--- head/lib/libutil/expand_number.c Wed Aug 21 22:30:11 2013 (r254620)
+++ head/lib/libutil/expand_number.c Wed Aug 21 22:37:15 2013 (r254621)
@@ -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;
More information about the svn-src-all
mailing list