From uqs@spoerlein.net  Sun Nov  8 10:57:28 2009
Return-Path: <uqs@spoerlein.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 062DB1065670
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Nov 2009 10:57:28 +0000 (UTC)
	(envelope-from uqs@spoerlein.net)
Received: from acme.spoerlein.net (cl-43.dus-01.de.sixxs.net [IPv6:2a01:198:200:2a::2])
	by mx1.freebsd.org (Postfix) with ESMTP id 88AE28FC14
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Nov 2009 10:57:27 +0000 (UTC)
Received: from coyote.spoerlein.net (e180129023.adsl.alicedsl.de [85.180.129.23])
	by acme.spoerlein.net (8.14.3/8.14.3) with ESMTP id nA8AvPou095081
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 8 Nov 2009 11:57:26 +0100 (CET)
	(envelope-from uqs@spoerlein.net)
Received: from coyote.spoerlein.net (localhost [127.0.0.1])
	by coyote.spoerlein.net (8.14.3/8.14.3) with ESMTP id nA8AvMoT024255
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Sun, 8 Nov 2009 11:57:23 +0100 (CET)
	(envelope-from uqs@coyote.spoerlein.net)
Received: (from uqs@localhost)
	by coyote.spoerlein.net (8.14.3/8.14.3/Submit) id nA8AvLYb024254;
	Sun, 8 Nov 2009 11:57:21 +0100 (CET)
	(envelope-from uqs)
Message-Id: <200911081057.nA8AvLYb024254@coyote.spoerlein.net>
Date: Sun, 8 Nov 2009 11:57:21 +0100 (CET)
From: Ulrich Spoerlein <uqs@spoerlein.net>
To: FreeBSD-gnats-submit@freebsd.org
Subject: chio(8) fix some harmless uninitialized argument warnings
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         140384
>Category:       bin
>Synopsis:       [patch] chio(8) fix some harmless uninitialized argument warnings
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    uqs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 08 11:00:07 UTC 2009
>Closed-Date:    Fri Jul 30 12:48:53 UTC 2010
>Last-Modified:  Fri Jul 30 12:48:53 UTC 2010
>Originator:     Ulrich Spoerlein
>Release:        FreeBSD 7.2-STABLE i386
>Organization:
>Environment:
	
>Description:
These were found by Clang/Static Analyzer

- Removed three dead increments
- More importantly, removes an uninitialized value read. While the zeroing
  of struct cesr upfront is enough and matches other parts of the code, I also
  removed the writing of a zero value into the struct, as it is unneeded. If
  this is deemed a superfluous optimization, just leave those assignments in.

see also:
https://www.spoerlein.net/scan-build/2009-11-07-1/report-wzs4FL.html#EndPath
https://www.spoerlein.net/scan-build/2009-11-07-1/report-apJ1ME.html#EndPath
https://www.spoerlein.net/scan-build/2009-11-07-1/report-Driys4.html#EndPath
https://www.spoerlein.net/scan-build/2009-11-07-1/report-4kHXS5.html#EndPath

>How-To-Repeat:
	
>Fix:
diff -r 4e4d5ca6b8da -r fdda05e4e407 bin/chio/chio.c
--- a/bin/chio/chio.c	Mon Nov 02 18:57:34 2009 +0100
+++ b/bin/chio/chio.c	Sun Nov 08 09:58:32 2009 +0100
@@ -424,16 +424,13 @@
 
 /* ARGSUSED */
 static int
-do_params(const char *cname, int argc, char **argv)
+do_params(const char *cname, int argc, char **argv __unused)
 {
 	struct changer_params data;
 	int picker;
 
 	/* No arguments to this command. */
-
-	++argv; --argc;
-
-	if (argc) {
+	if (argc > 1) {
 		warnx("%s: no arguments expected", cname);
 		goto usage;
 	}
@@ -467,15 +464,12 @@
 
 /* ARGSUSED */
 static int
-do_getpicker(const char *cname, int argc, char **argv)
+do_getpicker(const char *cname, int argc, char **argv __unused)
 {
 	int picker;
 
 	/* No arguments to this command. */
-
-	++argv; --argc;
-
-	if (argc) {
+	if (argc > 1) {
 		warnx("%s: no arguments expected", cname);
 		goto usage;
 	}
@@ -966,7 +960,6 @@
 	} else {
 		element = parse_element_unit(*argv);
 	}
-	++argv; --argc;
 
 	/* Get the status */
 	ces = get_element_status((unsigned int)type, (unsigned int)element,
@@ -1072,10 +1065,10 @@
 
 	/* Read in the changer slots */
 	if (cp.cp_nslots > 0) {
+		(void) memset(&cesr, 0, sizeof(cesr));
 		cesr.cesr_element_type = CHET_ST;
-		cesr.cesr_element_base = 0;
 		cesr.cesr_element_count = cp.cp_nslots;
-		cesr.cesr_flags |= CESR_VOLTAGS;
+		cesr.cesr_flags = CESR_VOLTAGS;
 		cesr.cesr_element_status = ces;
 
 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
@@ -1087,12 +1080,10 @@
 
 	/* Read in the drive information */
 	if (cp.cp_ndrives > 0 ) {
-
 		(void) memset(&cesr, 0, sizeof(cesr));
 		cesr.cesr_element_type = CHET_DT;
-		cesr.cesr_element_base = 0;
 		cesr.cesr_element_count = cp.cp_ndrives;
-		cesr.cesr_flags |= CESR_VOLTAGS;
+		cesr.cesr_flags = CESR_VOLTAGS;
 		cesr.cesr_element_status = ces;
 
 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
@@ -1106,9 +1097,8 @@
 	if (cp.cp_nportals > 0 ) {
 		(void) memset(&cesr, 0, sizeof(cesr));
 		cesr.cesr_element_type = CHET_IE;
-		cesr.cesr_element_base = 0;
 		cesr.cesr_element_count = cp.cp_nportals;
-		cesr.cesr_flags |= CESR_VOLTAGS;
+		cesr.cesr_flags = CESR_VOLTAGS;
 		cesr.cesr_element_status = ces;
 
 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
@@ -1122,9 +1112,8 @@
 	if (cp.cp_npickers > 0) {
 		(void) memset(&cesr, 0, sizeof(cesr));
 		cesr.cesr_element_type = CHET_MT;
-		cesr.cesr_element_base = 0;
 		cesr.cesr_element_count = cp.cp_npickers;
-		cesr.cesr_flags |= CESR_VOLTAGS;
+		cesr.cesr_flags = CESR_VOLTAGS;
 		cesr.cesr_element_status = ces;
 
 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
--- chio.diff ends here ---

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->uqs 
Responsible-Changed-By: uqs 
Responsible-Changed-When: Thu Feb 4 07:19:28 UTC 2010 
Responsible-Changed-Why:  
Assign my PRs to myself 

http://www.freebsd.org/cgi/query-pr.cgi?pr=140384 
State-Changed-From-To: open->patched 
State-Changed-By: uqs 
State-Changed-When: Wed Jun 2 09:36:02 UTC 2010 
State-Changed-Why:  
Important parts have been committed in r208730. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=140384 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/140384: commit references a PR
Date: Wed,  2 Jun 2010 09:34:56 +0000 (UTC)

 Author: uqs
 Date: Wed Jun  2 09:34:41 2010
 New Revision: 208730
 URL: http://svn.freebsd.org/changeset/base/208730
 
 Log:
   Zero struct before reading from it
   
   PR:	   140384
   Found by:  clang static analyzer
   MFC after: 3 weeks
 
 Modified:
   head/bin/chio/chio.c
 
 Modified: head/bin/chio/chio.c
 ==============================================================================
 --- head/bin/chio/chio.c	Wed Jun  2 08:43:18 2010	(r208729)
 +++ head/bin/chio/chio.c	Wed Jun  2 09:34:41 2010	(r208730)
 @@ -1072,6 +1072,7 @@ find_element(char *voltag, uint16_t *et,
  
  	/* Read in the changer slots */
  	if (cp.cp_nslots > 0) {
 +		(void) memset(&cesr, 0, sizeof(cesr));
  		cesr.cesr_element_type = CHET_ST;
  		cesr.cesr_element_base = 0;
  		cesr.cesr_element_count = cp.cp_nslots;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/140384: commit references a PR
Date: Fri, 30 Jul 2010 12:39:38 +0000 (UTC)

 Author: uqs
 Date: Fri Jul 30 12:36:40 2010
 New Revision: 210643
 URL: http://svn.freebsd.org/changeset/base/210643
 
 Log:
   MFC r208730:
   Zero struct before reading from it
   
   PR:		140384
 
 Modified:
   stable/8/bin/chio/chio.c
 Directory Properties:
   stable/8/bin/chio/   (props changed)
 
 Changes in other areas also in this revision:
 Modified:
   stable/7/bin/chio/chio.c
 Directory Properties:
   stable/7/bin/chio/   (props changed)
 
 Modified: stable/8/bin/chio/chio.c
 ==============================================================================
 --- stable/8/bin/chio/chio.c	Fri Jul 30 12:04:29 2010	(r210642)
 +++ stable/8/bin/chio/chio.c	Fri Jul 30 12:36:40 2010	(r210643)
 @@ -1072,6 +1072,7 @@ find_element(char *voltag, uint16_t *et,
  
  	/* Read in the changer slots */
  	if (cp.cp_nslots > 0) {
 +		(void) memset(&cesr, 0, sizeof(cesr));
  		cesr.cesr_element_type = CHET_ST;
  		cesr.cesr_element_base = 0;
  		cesr.cesr_element_count = cp.cp_nslots;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/140384: commit references a PR
Date: Fri, 30 Jul 2010 12:39:48 +0000 (UTC)

 Author: uqs
 Date: Fri Jul 30 12:36:40 2010
 New Revision: 210643
 URL: http://svn.freebsd.org/changeset/base/210643
 
 Log:
   MFC r208730:
   Zero struct before reading from it
   
   PR:		140384
 
 Modified:
   stable/7/bin/chio/chio.c
 Directory Properties:
   stable/7/bin/chio/   (props changed)
 
 Changes in other areas also in this revision:
 Modified:
   stable/8/bin/chio/chio.c
 Directory Properties:
   stable/8/bin/chio/   (props changed)
 
 Modified: stable/7/bin/chio/chio.c
 ==============================================================================
 --- stable/7/bin/chio/chio.c	Fri Jul 30 12:04:29 2010	(r210642)
 +++ stable/7/bin/chio/chio.c	Fri Jul 30 12:36:40 2010	(r210643)
 @@ -1072,6 +1072,7 @@ find_element(char *voltag, uint16_t *et,
  
  	/* Read in the changer slots */
  	if (cp.cp_nslots > 0) {
 +		(void) memset(&cesr, 0, sizeof(cesr));
  		cesr.cesr_element_type = CHET_ST;
  		cesr.cesr_element_base = 0;
  		cesr.cesr_element_count = cp.cp_nslots;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: uqs 
State-Changed-When: Fri Jul 30 12:48:51 UTC 2010 
State-Changed-Why:  
Merged to stable branches. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=140384 
>Unformatted:
