Re: svn commit: r295854 - head/bin/dd
On Sun, 21 Feb 2016, Edward Tomasz Napierala wrote: Log: Make the "invalid numeric value" error message actually displayable (was a dead code before). Submitted by: bde@ (earlier version) Reviewed by: bde@ Thanks. Modified: head/bin/dd/args.c Modified: head/bin/dd/args.c == --- head/bin/dd/args.c Sun Feb 21 13:54:22 2016(r295853) +++ head/bin/dd/args.c Sun Feb 21 14:36:50 2016(r295854) @@ -422,11 +422,10 @@ get_num(const char *val) errno = 0; num = strtoumax(val, &expr, 0); - if (errno != 0) /* Overflow or underflow. */ - err(1, "%s", oper); - if (expr == val)/* No valid digits. */ - errx(1, "%s: illegal numeric value", oper); + errx(1, "%s: invalid numeric value", oper); + if (errno != 0) + err(1, "%s", oper); mult = postfix_to_mult(*expr); ... This is to avoid the POSIX bug that the strto*() family "helpfully" sets errno for cases not specified by C90, C99 or C11. POSIX requires setting errno to EINVAL if the base is unsupported or no conversion could be performed. The FreeBSD man page says that the conversion error is unportable. The base error is equally unportable, but the man page doesn't mention it. This breaks code like the above which depends on the Standard C bhaviour of only setting errno to ERANGE. The code happens to do a generic check on errno first, and that prevents the more specific handling for a conversion error from being reached. Standard C in general allows errno to be clobbered on success, but for functions that are documented to set errno like the strto*() family, it intends to require only the documented settings. The above code is an example showing that settings to non-Standard C values are little different from gratuitous clobbering. Bruce ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r295854 - head/bin/dd
Author: trasz Date: Sun Feb 21 14:36:50 2016 New Revision: 295854 URL: https://svnweb.freebsd.org/changeset/base/295854 Log: Make the "invalid numeric value" error message actually displayable (was a dead code before). Submitted by: bde@ (earlier version) Reviewed by: bde@ MFC after:1 month Sponsored by: The FreeBSD Foundation Modified: head/bin/dd/args.c Modified: head/bin/dd/args.c == --- head/bin/dd/args.c Sun Feb 21 13:54:22 2016(r295853) +++ head/bin/dd/args.c Sun Feb 21 14:36:50 2016(r295854) @@ -422,11 +422,10 @@ get_num(const char *val) errno = 0; num = strtoumax(val, &expr, 0); - if (errno != 0) /* Overflow or underflow. */ - err(1, "%s", oper); - if (expr == val)/* No valid digits. */ - errx(1, "%s: illegal numeric value", oper); + errx(1, "%s: invalid numeric value", oper); + if (errno != 0) + err(1, "%s", oper); mult = postfix_to_mult(*expr); @@ -472,11 +471,10 @@ get_off_t(const char *val) errno = 0; num = strtoimax(val, &expr, 0); - if (errno != 0) /* Overflow or underflow. */ - err(1, "%s", oper); - if (expr == val)/* No valid digits. */ - errx(1, "%s: illegal numeric value", oper); + errx(1, "%s: invalid numeric value", oper); + if (errno != 0) + err(1, "%s", oper); mult = postfix_to_mult(*expr); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"