Date: Wed, 21 Aug 2013 22:37:16 +0000 (UTC) From: Sergey Kandaurov <pluknet@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254621 - head/lib/libutil Message-ID: <201308212237.r7LMbG8W043082@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308212237.r7LMbG8W043082>