bin/140384: chio(8) fix some harmless uninitialized argument warnings

Ulrich Spoerlein uqs at spoerlein.net
Sun Nov 8 11:00:08 UTC 2009


>Number:         140384
>Category:       bin
>Synopsis:       chio(8) fix some harmless uninitialized argument warnings
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 08 11:00:07 UTC 2009
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


More information about the freebsd-bugs mailing list