Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Nov 2001 15:09:34 +0300
From:      "Sergey A. Osokin" <osa@freebsd.org.ru>
To:        audit@FreeBSD.org
Subject:   date(1) WARNS=2 cleanup
Message-ID:  <20011123150934.A10406@freebsd.org.ru>

next in thread | raw e-mail | index | archive | help

--FL5UXtIhxfXey3p5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello.
Please review a patch for WARNS2'fy date(1).

Before commit, tsptype's type
(in src/include/protocols/timed.h) must be 
changed from (char *) to (const char *).

Another way is commit patch without changes
in src/bin/date/Makefile.

Thanks.
-- 

Rgdz,                                /"\ 
Sergey Osokin aka oZZ,               \ /  ASCII RIBBON CAMPAIGN
osa@freebsd.org.ru                    X     AGAINST HTML MAIL
http://freebsd.org.ru/~osa/          / \

--FL5UXtIhxfXey3p5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-date

diff -ruN date.orig/Makefile date/Makefile
--- date.orig/Makefile	Fri Nov 23 10:57:45 2001
+++ date/Makefile	Thu Nov 22 18:58:07 2001
@@ -6,4 +6,6 @@
 DPADD=	${LIBUTIL}
 LDADD=	-lutil
 
+WARNS?=	2
+
 .include <bsd.prog.mk>
diff -ruN date.orig/date.c date/date.c
--- date.orig/date.c	Fri Nov 23 10:57:45 2001
+++ date/date.c	Thu Nov 22 19:27:19 2001
@@ -71,7 +71,7 @@
 static void badformat __P((void));
 static void usage __P((void));
 
-int logwtmp __P((char *, char *, char *));
+int logwtmp __P((const char *, const char *, const char *));
 
 int
 main(argc, argv)
@@ -148,7 +148,7 @@
 	if (!rflag && time(&tval) == -1)
 		err(1, "time");
 
-	format = "%+";
+	format = strdup("%+");
 
 	/* allow the operands in any order */
 	if (*argv && **argv == '+') {
diff -ruN date.orig/netdate.c date/netdate.c
--- date.orig/netdate.c	Fri Nov 23 10:57:45 2001
+++ date/netdate.c	Thu Nov 22 19:55:07 2001
@@ -41,6 +41,7 @@
 
 #include <sys/param.h>
 #include <sys/time.h>
+#include <sys/types.h>
 #include <sys/socket.h>
 
 #include <netinet/in.h>
@@ -74,10 +75,10 @@
 	struct timeval tout;
 	struct servent *sp;
 	struct tsp msg;
-	struct sockaddr_in sin, dest, from;
+	struct sockaddr_in osin, dest, from;
 	fd_set ready;
 	long waittime;
-	int s, length, port, timed_ack, found, err;
+	int s, length, port, timed_ack, found, oerr;
 	char hostname[MAXHOSTNAMELEN];
 
 	if ((sp = getservbyname("timed", "udp")) == NULL) {
@@ -95,11 +96,11 @@
 		return (retval = 2);
 	}
 
-	memset(&sin, 0, sizeof(sin));
-	sin.sin_family = AF_INET;
+	memset(&osin, 0, sizeof(osin));
+	osin.sin_family = AF_INET;
 	for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) {
-		sin.sin_port = htons((u_short)port);
-		if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
+		osin.sin_port = htons((u_short)port);
+		if (bind(s, (struct sockaddr *)&osin, sizeof(osin)) >= 0)
 			break;
 		if (errno == EADDRINUSE)
 			continue;
@@ -143,11 +144,11 @@
 	FD_SET(s, &ready);
 	found = select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0, &tout);
 
-	length = sizeof(err);
+	length = sizeof(oerr);
 	if (!getsockopt(s,
-	    SOL_SOCKET, SO_ERROR, (char *)&err, &length) && err) {
-		if (err != ECONNREFUSED)
-			warnc(err, "send (delayed error)");
+	    SOL_SOCKET, SO_ERROR, (char *)&oerr, &length) && oerr) {
+		if (oerr != ECONNREFUSED)
+			warnc(oerr, "send (delayed error)");
 		goto bad;
 	}
 
diff -ruN date.orig/vary.c date/vary.c
--- date.orig/vary.c	Fri Nov 23 10:57:45 2001
+++ date/vary.c	Fri Nov 23 10:57:12 2001
@@ -37,7 +37,7 @@
 
 struct trans {
   int val;
-  char *str;
+  const char *str;
 };
 
 static struct trans trans_mon[] = {
@@ -47,7 +47,7 @@
   { -1, NULL }
 };
 
-static struct trans trans_wday[] = {
+static const struct trans trans_wday[] = {
   { 0, "sunday" }, { 1, "monday" }, { 2, "tuesday" }, { 3, "wednesday" },
   { 4, "thursday" }, { 5, "friday" }, { 6, "saturday" },
   { -1, NULL }
@@ -203,14 +203,14 @@
 static int
 adjday(struct tm *t, char type, int val, int mk)
 {
-  int mdays;
+  int omdays;
 
   switch (type) {
     case '+':
       while (val) {
-        mdays = daysinmonth(t);
-        if (val > mdays - t->tm_mday) {
-          val -= mdays - t->tm_mday + 1;
+        omdays = daysinmonth(t);
+        if (val > omdays - t->tm_mday) {
+          val -= omdays - t->tm_mday + 1;
           t->tm_mday = 1;
           if (!adjmon(t, '+', 1, 0, 0))
             return 0;
@@ -430,7 +430,7 @@
     if (type == '\0')
       t->tm_isdst = -1;
 
-    if (strspn(arg, digits) != len-1) {
+    if ((int)strspn(arg, digits) != len-1) {
       val = trans(trans_wday, arg);
       if (val != -1) {
           if (!adjwday(t, type, val, 1, 1))

--FL5UXtIhxfXey3p5--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011123150934.A10406>