From owner-svn-src-head@freebsd.org Mon Feb 22 06:27:16 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EFFBEAB0BAE; Mon, 22 Feb 2016 06:27:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail107.syd.optusnet.com.au (mail107.syd.optusnet.com.au [211.29.132.53]) by mx1.freebsd.org (Postfix) with ESMTP id B779D1DF0; Mon, 22 Feb 2016 06:27:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c110-21-41-193.carlnfd1.nsw.optusnet.com.au (c110-21-41-193.carlnfd1.nsw.optusnet.com.au [110.21.41.193]) by mail107.syd.optusnet.com.au (Postfix) with ESMTPS id 52C8FD44F87; Mon, 22 Feb 2016 17:27:15 +1100 (AEDT) Date: Mon, 22 Feb 2016 17:27:15 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Edward Tomasz Napierala cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r295854 - head/bin/dd In-Reply-To: <201602211436.u1LEaokw063705@repo.freebsd.org> Message-ID: <20160222165540.W887@besplex.bde.org> References: <201602211436.u1LEaokw063705@repo.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=EfU1O6SC c=1 sm=1 tr=0 a=73JWPhLeruqQCjN69UNZtQ==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=0lN02kvMIj7ZGMO8T6wA:9 a=JEOMfYCwILfcGJts:21 a=gc74SzTQ1ZaEyj_F:21 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2016 06:27:17 -0000 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