atacontrol(8) warns=5 and strcmp cleanup

"Simon L. Nielsen" <[email protected]> Thu, 17 Apr 2003 02:37:33 +0200
Newsgroups gmane.os.freebsd.devel.audit
Message-ID <[email protected]>
Hello

Attached is two patches for atacontrol(8).

The first makes it WARNS=5 safe. It works on i386 but the only non i386
I have access to an Alpha running 4.7 so there could problems for non
i386. A slightly modified version of the patch compiles on the 4.7 Alpha
so I think it should be ok.

The other patch makes the the strcmp checks more clear. In short :
s/!strcmp()/strcmp() == 0/ and s/strcmp()/strcmp() != 0/.

The generated object file is not changed by either patch.

Btw. I posted the patch to -arch since an old PR about WARNS fixes
suggested posting here instead of filing a PR.

-- 
Simon L. Nielsen
atacontrol-warns5.patch (text/plain, 1.6 KB)
--- atacontrol.c.orig	Thu Apr 17 02:01:59 2003
+++ atacontrol.c	Thu Apr 17 02:01:01 2003
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/ata.h>
 
+#include <inttypes.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -38,7 +39,17 @@
 #include <stdlib.h>
 #include <string.h>
 
-char *
+/* Prototypes */
+const char	*mode2str(int mode);
+int		 str2mode(char *str);
+void		 usage(void);
+int		 version(int ver);
+void		 param_print(struct ata_params *parm);
+void		 cap_print(struct ata_params *parm);
+int		 ata_cap_print(int fd, int channel, int device);
+int		 info_print(int fd, int channel, int prchan);
+
+const char *
 mode2str(int mode)
 {
 	switch (mode) {
@@ -88,14 +99,14 @@
 }
 
 int
-version(int version)
+version(int ver)
 {
 	int bit;
     
-	if (version == 0xffff)
+	if (ver == 0xffff)
 		return 0;
 	for (bit = 15; bit >= 0; bit--)
-		if (version & (1<<bit))
+		if (ver & (1<<bit))
 			return bit;
     	return 0;
 }
@@ -137,7 +148,7 @@
 	printf("lba48%ssupported         ",
 		parm->support.address48 ? " " : " not ");
 	if (lbasize48)
-		printf("%lld sectors\n", lbasize48);	
+		printf("%"PRId64" sectors\n", lbasize48);
 	else
 		printf("\n");
 
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/sbin/atacontrol/Makefile,v
retrieving revision 1.6
diff -u -d -r1.6 Makefile
--- Makefile	4 Dec 2001 02:19:43 -0000	1.6
+++ Makefile	17 Apr 2003 00:15:20 -0000
@@ -1,7 +1,7 @@
 #$FreeBSD: src/sbin/atacontrol/Makefile,v 1.6 2001/12/04 02:19:43 obrien Exp $
 
 PROG=	atacontrol
-WARNS=	0
+WARNS=	5
 MAN=	atacontrol.8
 
 .include <bsd.prog.mk>
atacontrol-strcmp.patch (text/plain, 4.2 KB)
Index: atacontrol.c
===================================================================
RCS file: /home/ncvs/src/sbin/atacontrol/atacontrol.c,v
retrieving revision 1.20
retrieving revision 1.20.1002.1
diff -u -d -r1.20 -r1.20.1002.1
--- atacontrol.c	22 Mar 2003 12:18:20 -0000	1.20
+++ atacontrol.c	16 Apr 2003 22:37:49 -0000	1.20.1002.1
@@ -259,12 +259,12 @@
 
 	bzero(&iocmd, sizeof(struct ata_cmd));
 
-	if (argc > 2 && strcmp(argv[1], "create")) {
+	if (argc > 2 && strcmp(argv[1], "create") != 0) {
 		int chan;
 
-		if (!strcmp(argv[1], "delete") ||
-		    !strcmp(argv[1], "status") ||
-		    !strcmp(argv[1], "rebuild")) {
+		if (strcmp(argv[1], "delete") == 0 ||
+		    strcmp(argv[1], "status") == 0 ||
+		    strcmp(argv[1], "rebuild") == 0) {
 			if (!(sscanf(argv[2], "%d", &chan) == 1 ||
 			      sscanf(argv[2], "ar%d", &chan) == 1))
 				usage();
@@ -277,7 +277,7 @@
 		iocmd.channel = chan;
 	}
 
-	if (!strcmp(argv[1], "list") && argc == 2) {
+	if (strcmp(argv[1], "list") == 0 && argc == 2) {
 		iocmd.cmd = ATAGMAXCHANNEL;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
 			err(1, "ioctl(ATAGMAXCHANNEL)");
@@ -285,13 +285,13 @@
 		for (unit = 0; unit < maxunit; unit++)
 			info_print(fd, unit, 1);
 	}
-	else if (!strcmp(argv[1], "info") && argc == 3) {
+	else if (strcmp(argv[1], "info") == 0 && argc == 3) {
 		info_print(fd, iocmd.channel, 0);
 	}
-	else if (!strcmp(argv[1], "cap") && argc == 4) {
+	else if (strcmp(argv[1], "cap") == 0 && argc == 4) {
 		ata_cap_print(fd, iocmd.channel, atoi(argv[3]));
 	}
-	else if (!strcmp(argv[1], "enclosure") && argc == 4) {
+	else if (strcmp(argv[1], "enclosure") == 0 && argc == 4) {
 		iocmd.device = atoi(argv[3]);
 		iocmd.cmd = ATAENCSTAT;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
@@ -302,34 +302,37 @@
 			(double)iocmd.u.enclosure.v05 / 1000,
 			(double)iocmd.u.enclosure.v12 / 1000);
 	}
-	else if (!strcmp(argv[1], "detach") && argc == 3) {
+	else if (strcmp(argv[1], "detach") == 0 && argc == 3) {
 		iocmd.cmd = ATADETACH;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
 			err(1, "ioctl(ATADETACH)");
 	}
-	else if (!strcmp(argv[1], "attach") && argc == 3) {
+	else if (strcmp(argv[1], "attach") == 0 && argc == 3) {
 		iocmd.cmd = ATAATTACH;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
 			err(1, "ioctl(ATAATTACH)");
 		info_print(fd, iocmd.channel, 0);
 	}
-	else if (!strcmp(argv[1], "reinit") && argc == 3) {
+	else if (strcmp(argv[1], "reinit") == 0 && argc == 3) {
 		iocmd.cmd = ATAREINIT;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
 			warn("ioctl(ATAREINIT)");
 		info_print(fd, iocmd.channel, 0);
 	}
-	else if (!strcmp(argv[1], "create")) {
+	else if (strcmp(argv[1], "create") == 0) {
 		int disk, dev, offset;
 
 		iocmd.cmd = ATARAIDCREATE;
-		if (!strcmp(argv[2], "RAID0") || !strcmp(argv[2], "stripe"))
+		if (strcmp(argv[2], "RAID0") == 0 ||
+		    strcmp(argv[2], "stripe") == 0)
 			iocmd.u.raid_setup.type = 1;
-		if (!strcmp(argv[2], "RAID1") || !strcmp(argv[2],"mirror"))
+		if (strcmp(argv[2], "RAID1") == 0 ||
+		    strcmp(argv[2],"mirror") == 0)
 			iocmd.u.raid_setup.type = 2;
-		if (!strcmp(argv[2], "RAID0+1"))
+		if (strcmp(argv[2], "RAID0+1") == 0)
 			iocmd.u.raid_setup.type = 3;
-		if (!strcmp(argv[2], "SPAN") || !strcmp(argv[2], "JBOD"))
+		if (strcmp(argv[2], "SPAN") == 0 ||
+		    strcmp(argv[2], "JBOD") == 0)
 			iocmd.u.raid_setup.type = 4;
 		if (!iocmd.u.raid_setup.type)
 		     usage();
@@ -355,17 +358,17 @@
 		else
 			printf("ar%d created\n", iocmd.u.raid_setup.unit);
 	}
-	else if (!strcmp(argv[1], "delete") && argc == 3) {
+	else if (strcmp(argv[1], "delete") == 0 && argc == 3) {
 		iocmd.cmd = ATARAIDDELETE;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
 			warn("ioctl(ATARAIDDELETE)");
 	}
-	else if (!strcmp(argv[1], "rebuild") && argc == 3) {
+	else if (strcmp(argv[1], "rebuild") == 0 && argc == 3) {
 		iocmd.cmd = ATARAIDREBUILD;
 		if (ioctl(fd, IOCATA, &iocmd) < 0)
 			warn("ioctl(ATARAIDREBUILD)");
 	}
-	else if (!strcmp(argv[1], "status") && argc == 3) {
+	else if (strcmp(argv[1], "status") == 0 && argc == 3) {
 		int i;
 
 		iocmd.cmd = ATARAIDSTATUS;
@@ -409,7 +412,7 @@
 			printf("BROKEN\n");
 		}
 	}
-	else if (!strcmp(argv[1], "mode") && (argc == 3 || argc == 5)) {
+	else if (strcmp(argv[1], "mode") == 0 && (argc == 3 || argc == 5)) {
 		if (argc == 5) {
 			iocmd.cmd = ATASMODE;
 			iocmd.device = -1;
signature.asc (application/pgp-signature, 187 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+nfdM8kocFXgPTRwRAnyaAJ9GjRP0qexZii4wJRd/aTO9hK2jzwCgvQBe
QkJot4opkkcA2/l2pusSd0A=
=2JLY
-----END PGP SIGNATURE-----