Mon Mar 16 00:08:10 2009 UTC ()
fix WARNS=3 issues;
* sprinkle const
* avoid tests < 0 on unsigned types
* test fwrite() returns nmemb not <0


(lukem)
diff -r1.4 -r1.5 src/libexec/lfs_cleanerd/cleaner.h
diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/coalesce.c
diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/lfs_cleanerd.c

cvs diff -r1.4 -r1.5 src/libexec/lfs_cleanerd/cleaner.h (expand / switch to context diff)
--- src/libexec/lfs_cleanerd/cleaner.h 2006/07/31 16:34:42 1.4
+++ src/libexec/lfs_cleanerd/cleaner.h 2009/03/16 00:08:10 1.5
@@ -49,7 +49,7 @@
 void pwarn(const char *, ...);
 void calc_cb(struct clfs *, int, struct clfs_seguse *);
 int clean_fs(struct clfs *, CLEANERINFO *);
-void dlog(char *, ...);
+void dlog(const char *, ...);
 void handle_error(struct clfs **, int);
 int init_fs(struct clfs *, char *);
 int invalidate_segment(struct clfs *, int);

cvs diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/coalesce.c (expand / switch to context diff)
--- src/libexec/lfs_cleanerd/coalesce.c 2008/05/16 09:21:59 1.16
+++ src/libexec/lfs_cleanerd/coalesce.c 2009/03/16 00:08:10 1.17
@@ -1,4 +1,4 @@
-/*      $NetBSD: coalesce.c,v 1.16 2008/05/16 09:21:59 hannken Exp $  */
+/*      $NetBSD: coalesce.c,v 1.17 2009/03/16 00:08:10 lukem Exp $  */
 
 /*-
  * Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
@@ -87,7 +87,7 @@
 	COALESCE_MAXERROR
 };
 
-char *coalesce_return[] = {
+const char *coalesce_return[] = {
 	"Successfully coalesced",
 	"File not in use or inode not found",
 	"Not large enough to coalesce",
@@ -167,11 +167,13 @@
 	}
 
 	/* Sanity checks */
+#if 0	/* di_size is uint64_t -- this is a noop */
 	if (dip->di_size < 0) {
 		dlog("ino %d, negative size (%" PRId64 ")", ino, dip->di_size);
 		free(dip);
 		return COALESCE_BADSIZE;
 	}
+#endif
 	if (nb > dip->di_blocks) {
 		dlog("ino %d, computed blocks %d > held blocks %d", ino, nb,
 		     dip->di_blocks);

cvs diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/lfs_cleanerd.c (expand / switch to context diff)
--- src/libexec/lfs_cleanerd/lfs_cleanerd.c 2009/03/15 23:56:24 1.16
+++ src/libexec/lfs_cleanerd/lfs_cleanerd.c 2009/03/16 00:08:10 1.17
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_cleanerd.c,v 1.16 2009/03/15 23:56:24 lukem Exp $	 */
+/* $NetBSD: lfs_cleanerd.c,v 1.17 2009/03/16 00:08:10 lukem Exp $	 */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -99,7 +99,7 @@
  * Log a message if debugging is turned on.
  */
 void
-dlog(char *fmt, ...)
+dlog(const char *fmt, ...)
 {
 	va_list ap;
 
@@ -599,7 +599,7 @@
 
         fp = fopen(copylog_filename, "ab");
         if (fp != NULL) {
-                if (fwrite(cp, (size_t)fs->lfs_ssize, 1, fp) < 0) {
+                if (fwrite(cp, (size_t)fs->lfs_ssize, 1, fp) != 1) {
                         perror("writing segment to copy log");
                 }
         }
@@ -684,7 +684,7 @@
 		return;
 	}
 
-	if (t->nbytes < 0 || t->nbytes > fs->lfs_ssize) {
+	if (t->nbytes > fs->lfs_ssize) {
 		/* Another type of error */
 		syslog(LOG_WARNING, "segment %d: bad seguse count %d",
 		       sn, t->nbytes);
@@ -725,10 +725,10 @@
 static int
 bi_comparator(const void *va, const void *vb)
 {
-	BLOCK_INFO *a, *b;
+	const BLOCK_INFO *a, *b;
 
-	a = (BLOCK_INFO *)va;
-	b = (BLOCK_INFO *)vb;
+	a = (const BLOCK_INFO *)va;
+	b = (const BLOCK_INFO *)vb;
 
 	/* Check for out-of-place block */
 	if (a->bi_segcreate == a->bi_daddr &&
@@ -765,10 +765,10 @@
 static int
 cb_comparator(const void *va, const void *vb)
 {
-	struct clfs_seguse *a, *b;
+	const struct clfs_seguse *a, *b;
 
-	a = *(struct clfs_seguse **)va;
-	b = *(struct clfs_seguse **)vb;
+	a = *(const struct clfs_seguse * const *)va;
+	b = *(const struct clfs_seguse * const *)vb;
 	return a->priority > b->priority ? -1 : 1;
 }