From owner-svn-src-all@FreeBSD.ORG Sat Aug 9 01:16:01 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 704CA3C3; Sat, 9 Aug 2014 01:16:01 +0000 (UTC) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 32C8F2667; Sat, 9 Aug 2014 01:16:00 +0000 (UTC) Received: from c122-106-147-133.carlnfd1.nsw.optusnet.com.au (c122-106-147-133.carlnfd1.nsw.optusnet.com.au [122.106.147.133]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 41ED4782531; Sat, 9 Aug 2014 10:52:46 +1000 (EST) Date: Sat, 9 Aug 2014 10:52:45 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Sean Bruno Subject: Re: svn commit: r269741 - head/sys/boot/userboot/userboot In-Reply-To: <53e54583.2353.2c317825@svn.freebsd.org> Message-ID: <20140809101837.O1460@besplex.bde.org> References: <53e54583.2353.2c317825@svn.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=BdjhjNd2 c=1 sm=1 tr=0 a=7NqvjVvQucbO2RlWB8PEog==:117 a=PO7r1zJSAAAA:8 a=41dIonQiZJoA:10 a=r3wscOWN9QkA:10 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=2WM0o05XAXqP8Rit2SYA:9 a=jR_EQs_rrjgG2URe:21 a=gn4EcROLcvGEgZUk:21 a=CjuIK1q_8ugA:10 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Aug 2014 01:16:01 -0000 On Fri, 8 Aug 2014, Sean Bruno wrote: > Log: > Quiesce warning about discarding a const qualifier in assignement. This replaces an error by another error. (Non-C compilers like clang and gcc give only a warning for the first error and not even a warning for the second error when it is quiesced.) > Modified: head/sys/boot/userboot/userboot/devicename.c > ============================================================================== > --- head/sys/boot/userboot/userboot/devicename.c Fri Aug 8 21:27:33 2014 (r269740) > +++ head/sys/boot/userboot/userboot/devicename.c Fri Aug 8 21:47:47 2014 (r269741) > @@ -91,7 +91,7 @@ userboot_parsedev(struct disk_devdesc ** > struct disk_devdesc *idev; > struct devsw *dv; > int i, unit, err; > - char *cp; > + const char *cp; > const char *np; > > /* minimum length check */ This code also has bad style, with unsorted declarations and indentation in all the wrong places. Local declarations are not indented in KNF, but are excessively indented here. Statements are Indented by 1 tab in KNF, but by only 4 spaces here. > @@ -126,7 +126,7 @@ userboot_parsedev(struct disk_devdesc ** > unit = 0; > > if (*np && (*np != ':')) { > - unit = strtol(np, &cp, 0); /* get unit number if present */ > + unit = strtol(np, (char **)&cp, 0); /* get unit number if present */ > if (cp == np) { > err = EUNIT; > goto fail; A C compiler (TenDRA) says: "userboot.c", line 129: Error: [ISO C90 6.3.2.2]: In call of function 'strtol'. [ISO C90 6.1.2.6]: The types 'const char *' and 'char *' are incompatible. [ISO C90 6.3.4]: Types in pointer conversion should be compatible. [ISO C90 6.3.16]: Can't perform this conversion by assignment. [ISO C90 6.3.2.2]: Argument 2 is converted to parameter type. This is a well known problem in the strtol() API. endptr in it cannot have const qualifiers, and even bogus casts to remove the qualifiers are errors. In the above, you applied a bogus cast to break a warning that should be an error, but the cast itself is an error. Correct code: char *xcp; ... unit = strtol(np, &xcp, 0); /* banal comment deleted */ cp = xcp; strtol() must be passed a char **, not something else bogusly cast to break the warning that should be an error. Then it returns a char * (in xcp here). This can be assigned to a const char * with no problems. One reason strtol() takes doesn't take consts in its endptr is that if it returned a const char * then you couldn't assign it to a char * without problems. Note that calling strtol() reduces type safety, but no worse than strchr(). You start with a const char * like np and get back a plain char * like xcp. Assigning to *xcp would be an error. The only clearly safe use of the result is to assign xcp it to a const char * like cp above before using it. This is only needed when np is const char * of course. Bruce