Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Feb 2016 17:27:15 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Edward Tomasz Napierala <trasz@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r295854 - head/bin/dd
Message-ID:  <20160222165540.W887@besplex.bde.org>
In-Reply-To: <201602211436.u1LEaokw063705@repo.freebsd.org>
References:  <201602211436.u1LEaokw063705@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160222165540.W887>