Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 03 Dec 2001 21:55:54 +0000
From:      David Malone <dwmalone@maths.tcd.ie>
To:        audit@freebsd.org
Cc:        markm@freebsd.org
Subject:   Warns for tcopy and wc.
Message-ID:   <200112032155.aa79655@salmon.maths.tcd.ie>

next in thread | raw e-mail | index | archive | help
I have warns patches for tcopy and wc, but they run into the
following problems.

	1) If people want to count something big then they often
	use int64_t. Unfortunately these are defined in terms of
	different types on the alpha and i386 (long and long long
	respectively).  This means that printfing these requires
	a cast, so in some cases it seems to make more sense to
	just use a long long (which C99 says is at least 64 bits).

	2) As far as I know, %qd is for printing quat_t and %lld
	is for printing long longs. Unfortunately our gcc doesn't
	seem to know this and thinks that %qd is for printing long
	longs. Until this is fixed it means that quad_t's are as
	hard to print as int64_t.

'cos of these two problems, I arrived at the following patches
which use long longs in preference to either quad_t or int64_t.
Any comments on if this should be committed?

	David.



Index: tcopy/Makefile
===================================================================
RCS file: /home/ncvs/src/usr.bin/tcopy/Makefile,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 Makefile
--- tcopy/Makefile	27 May 1994 12:32:47 -0000	1.1.1.1
+++ tcopy/Makefile	3 Dec 2001 20:54:29 -0000
@@ -1,5 +1,6 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
 
 PROG=	tcopy
+WARNS?=	2
 
 .include <bsd.prog.mk>
Index: tcopy/tcopy.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/tcopy/tcopy.c,v
retrieving revision 1.9
diff -u -u -r1.9 tcopy.c
--- tcopy/tcopy.c	13 Aug 2001 21:58:16 -0000	1.9
+++ tcopy/tcopy.c	3 Dec 2001 21:44:29 -0000
@@ -64,7 +64,7 @@
 #define	NOCOUNT	(-2)
 
 int	filen, guesslen, maxblk = MAXREC;
-u_int64_t	lastrec, record, size, tsize;
+unsigned long long	lastrec, record, size, tsize;
 FILE	*msg;
 
 void	*getspace __P((int));
@@ -83,7 +83,8 @@
 	enum {READ, VERIFY, COPY, COPYVERIFY} op = READ;
 	sig_t oldsig;
 	int ch, needeof;
-	char *buff, *inf;
+	char *buff;
+	const char *inf;
 
 	msg = stdout;
 	guesslen = 1;
@@ -157,16 +158,16 @@
 				if (nread >= 0)
 					goto r1;
 			}
-			err(1, "read error, file %d, record %qu", filen, record);
+			err(1, "read error, file %d, record %llu", filen, record);
 		} else if (nread != lastnread) {
 			if (lastnread != 0 && lastnread != NOCOUNT) {
 				if (lastrec == 0 && nread == 0)
-					fprintf(msg, "%qu records\n", record);
+					fprintf(msg, "%llu records\n", record);
 				else if (record - lastrec > 1)
-					fprintf(msg, "records %qu to %qu\n",
+					fprintf(msg, "records %llu to %llu\n",
 					    lastrec, record);
 				else
-					fprintf(msg, "record %qu\n", lastrec);
+					fprintf(msg, "record %llu\n", lastrec);
 			}
 			if (nread != 0)
 				fprintf(msg, "file %d: block size %d: ",
@@ -184,9 +185,9 @@
 				nw = write(outp, buff, nread);
 				if (nw != nread) {
 					if (nw == -1) {
-					warn("write error, file %d, record %qu", filen, record);
+					warn("write error, file %d, record %llu", filen, record);
 					} else {
-					warnx("write error, file %d, record %qu", filen, record);
+					warnx("write error, file %d, record %llu", filen, record);
 					warnx("write (%d) != read (%d)", nw, nread);
 					}
 					errx(5, "copy aborted");
@@ -200,7 +201,7 @@
 				break;
 			}
 			fprintf(msg,
-			    "file %d: eof after %qu records: %qu bytes\n",
+			    "file %d: eof after %llu records: %llu bytes\n",
 			    filen, record, size);
 			needeof = 1;
 			filen++;
@@ -210,7 +211,7 @@
 		}
 		lastnread = nread;
 	}
-	fprintf(msg, "total length: %qu bytes\n", tsize);
+	fprintf(msg, "total length: %llu bytes\n", tsize);
 	(void)signal(SIGINT, oldsig);
 	if (op == COPY || op == COPYVERIFY) {
 		writeop(outp, MTWEOF);
@@ -280,16 +281,16 @@
 
 void
 intr(signo)
-	int signo;
+	int signo __unused;
 {
 	if (record) {
 		if (record - lastrec > 1)
-			fprintf(msg, "records %qu to %qu\n", lastrec, record);
+			fprintf(msg, "records %llu to %llu\n", lastrec, record);
 		else
-			fprintf(msg, "record %qu\n", lastrec);
+			fprintf(msg, "record %llu\n", lastrec);
 	}
-	fprintf(msg, "interrupt at file %d: record %qu\n", filen, record);
-	fprintf(msg, "total length: %ld bytes\n", tsize + size);
+	fprintf(msg, "interrupt at file %d: record %llu\n", filen, record);
+	fprintf(msg, "total length: %lld bytes\n", tsize + size);
 	exit(1);
 }
 
Index: wc/Makefile
===================================================================
RCS file: /home/ncvs/src/usr.bin/wc/Makefile,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 Makefile
--- wc/Makefile	27 May 1994 12:33:28 -0000	1.1.1.1
+++ wc/Makefile	3 Dec 2001 20:54:29 -0000
@@ -1,5 +1,6 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
 
 PROG=	wc
+WARNS?=	2
 
 .include <bsd.prog.mk>
Index: wc/wc.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/wc/wc.c,v
retrieving revision 1.11
diff -u -u -r1.11 wc.c
--- wc/wc.c	28 Aug 1999 01:07:34 -0000	1.11
+++ wc/wc.c	3 Dec 2001 20:54:29 -0000
@@ -58,10 +58,10 @@
 #include <string.h>
 #include <unistd.h>
 
-u_quad_t tlinect, twordct, tcharct;
+unsigned long long tlinect, twordct, tcharct;
 int doline, doword, dochar;
 
-int cnt __P((char *));
+int cnt __P((const char *));
 void usage __P((void));
 
 int
@@ -113,11 +113,11 @@
 
 	if (total > 1) {
 		if (doline)
-			(void)printf(" %7qu", tlinect);
+			(void)printf(" %7llu", tlinect);
 		if (doword)
-			(void)printf(" %7qu", twordct);
+			(void)printf(" %7llu", twordct);
 		if (dochar)
-			(void)printf(" %7qu", tcharct);
+			(void)printf(" %7llu", tcharct);
 		(void)printf(" total\n");
 	}
 	exit(errors == 0 ? 0 : 1);
@@ -125,10 +125,10 @@
 
 int
 cnt(file)
-	char *file;
+	const char *file;
 {
 	struct stat sb;
-	u_quad_t linect, wordct, charct;
+	unsigned long long linect, wordct, charct;
 	int fd, len;
 	short gotsp;
 	u_char *p;
@@ -163,10 +163,10 @@
 						++linect;
 			}
 			tlinect += linect;
-			(void)printf(" %7qu", linect);
+			(void)printf(" %7llu", linect);
 			if (dochar) {
 				tcharct += charct;
-				(void)printf(" %7qu", charct);
+				(void)printf(" %7llu", charct);
 			}
 			(void)close(fd);
 			return (0);
@@ -217,15 +217,15 @@
 	}
 	if (doline) {
 		tlinect += linect;
-		(void)printf(" %7qu", linect);
+		(void)printf(" %7llu", linect);
 	}
 	if (doword) {
 		twordct += wordct;
-		(void)printf(" %7qu", wordct);
+		(void)printf(" %7llu", wordct);
 	}
 	if (dochar) {
 		tcharct += charct;
-		(void)printf(" %7qu", charct);
+		(void)printf(" %7llu", charct);
 	}
 	(void)close(fd);
 	return (0);

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? <200112032155.aa79655>