commit ad345c6ff8597683f51ec37daaa300bcacc6f35e
Author: Tim Woodall <tim@woodall.me.uk>
Date:   Sun Sep 29 19:21:06 2024 +0100

    Silence LSP warnings

--- a/common/dumprmt.c
+++ b/common/dumprmt.c
@@ -206,7 +206,6 @@ rmtgetconn(void)
 		tuser = pwd->pw_name;
 	if ((rmt = getenv("RMT")) == NULL)
 		rmt = _PATH_RMT;
-	msg("");
 
 	if (rsh) {
 		const char *rshcmd[6];
@@ -339,9 +338,9 @@ rmtwrite(const char *buf, size_t count)
 	char line[30];
 
 	(void)snprintf(line, sizeof (line), "W%ld\n", (long)count);
-	if (write(tormtape, line, strlen(line)) != strlen(line))
+	if (write(tormtape, line, strlen(line)) != (long)strlen(line))
 		return -1;
-	if (write(tormtape, buf, count) != count)
+	if (write(tormtape, buf, count) != (long)count)
 		return -1;
 	return (rmtreply("write"));
 }
@@ -368,7 +367,7 @@ rmtstatus(void)
 	i = rmtcall("status", "S");
 	if (i < 0) return NULL;
 	if (i != (int)sizeof(mts)) {
-		msg("mtget sizes different between host (%d) "
+		msg("mtget sizes different between host (%lu) "
 		    "and remote tape (%d)", sizeof(mts), i);
 		for ( /* empty */; i > 0; --i)
 			rmtgetb();
--- a/common/legacy_indexer.c
+++ b/common/legacy_indexer.c
@@ -159,7 +159,7 @@ legacy_foo()
  * Dump inode
  */
 static int
-legacy_addInode(struct dinode *dp, dump_ino_t ino, int metaonly)
+legacy_addInode(UNUSED(struct dinode *dp), UNUSED(dump_ino_t ino), UNUSED(int metaonly))
 {
 	return 0;
 }
@@ -168,7 +168,7 @@ legacy_addInode(struct dinode *dp, dump_
  * Dump directory (dirent) entry
  */
 static int
-legacy_addDirEntry(struct direct *dp, dump_ino_t parent_ino)
+legacy_addDirEntry(UNUSED(struct direct *dp), UNUSED(dump_ino_t parent_ino))
 {
 	 return 0;
 }
--- a/common/slave.h
+++ b/common/slave.h
@@ -6,6 +6,8 @@
 #ifndef _SLAVE_H
 #define _SLAVE_H 1
 
+#include <protocols/dumprestore.h>
+
 /*
  * Concurrent dump mods (Caltech) - disk block reading and tape writing
  * are exported to several slave processes.  While one slave writes the
--- a/common/transformation.h
+++ b/common/transformation.h
@@ -25,6 +25,7 @@
 typedef struct transformation {
 	int enc;
 	union {
+		int initval__;
 #ifdef HAVE_LZO
 		struct {
 			lzo_align_t __LZO_MMODEL *LZO_WorkMem;
--- a/common/transformation_bzlib.c
+++ b/common/transformation_bzlib.c
@@ -11,7 +11,7 @@
  * Initialize
  */
 static int
-bzlib_initialize(Transformation *xform, int enc)
+bzlib_initialize(UNUSED(Transformation *xform), UNUSED(int enc))
 {
 	return 0;
 }
@@ -20,7 +20,7 @@ bzlib_initialize(Transformation *xform,
  * Shut down.
  */
 static int
-bzlib_shutdown(Transformation *xform)
+bzlib_shutdown(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -29,8 +29,8 @@ bzlib_shutdown(Transformation *xform)
  * Handle forks.
  */
 static int
-bzlib_startNewTape(Transformation *xform, struct tapebuf *tpbin,
-	unsigned long *destlen)
+bzlib_startNewTape(UNUSED(Transformation *xform), UNUSED(struct tapebuf *tpbin),
+	UNUSED(unsigned long *destlen))
 {
 	return 0;
 }
@@ -39,7 +39,7 @@ bzlib_startNewTape(Transformation *xform
  * Start slave process.
  */
 static int
-bzlib_startDiskIOProcess(Transformation *xform)
+bzlib_startDiskIOProcess(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -83,7 +83,7 @@ bzlib_compress(Transformation *xform, st
  * Decompress a buffer.
  */
 static int
-bzlib_decompress(Transformation *xform, struct tapebuf *tpbin,
+bzlib_decompress(UNUSED(Transformation *xform), struct tapebuf *tpbin,
 		unsigned long *destlen, const char *src, int srclen, char **reason) {
 #ifdef HAVE_BZLIB
 	int cresult;
--- a/common/transformation_lzo.c
+++ b/common/transformation_lzo.c
@@ -11,7 +11,7 @@
  * Initialize
  */
 static int
-lzo_initialize(Transformation *xform, int enc)
+lzo_initialize(UNUSED(Transformation *xform), UNUSED(int enc))
 {
 	return 0;
 }
@@ -20,7 +20,7 @@ lzo_initialize(Transformation *xform, in
  * Shut down.
  */
 static int
-lzo_shutdown(Transformation *xform)
+lzo_shutdown(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -29,8 +29,8 @@ lzo_shutdown(Transformation *xform)
  * Handle forks.
  */
 static int
-lzo_startNewTape(Transformation *xform, struct tapebuf *tpbin,
-	unsigned long *destlen)
+lzo_startNewTape(UNUSED(Transformation *xform), UNUSED(struct tapebuf *tpbin),
+	UNUSED(unsigned long *destlen))
 {
 	return 0;
 }
@@ -39,7 +39,7 @@ lzo_startNewTape(Transformation *xform,
  * Start slave process.
  */
 static int
-lzo_startDiskIOProcess(Transformation *xform)
+lzo_startDiskIOProcess(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -73,7 +73,7 @@ lzo_compress(Transformation *xform, stru
 	lzo_uint *worklen2 = (lzo_uint *) destlen;
 	int compresult;
 
-	compresult = lzo1x_1_compress(src, srclen, tpbin->buf, worklen2,
+	compresult = lzo1x_1_compress((const unsigned char*)src, srclen, (unsigned char*)tpbin->buf, worklen2,
 			xform->state.lzo.LZO_WorkMem);
 
 	return compresult == LZO_E_OK ? 1 : 0;
@@ -86,13 +86,13 @@ lzo_compress(Transformation *xform, stru
  * Decompress a buffer.
  */
 static int
-lzo_decompress(Transformation *xform, struct tapebuf *tpbin,
+lzo_decompress(UNUSED(Transformation *xform), struct tapebuf *tpbin,
 		unsigned long *destlen, const char *src, int srclen, char **reason)
 {
 #ifdef HAVE_LZO
 	int cresult = 0;
 	lzo_uint destlen2 = *destlen;
-	cresult = lzo1x_decompress(src, srclen, tpbin->buf, &destlen2, NULL);
+	cresult = lzo1x_decompress((const unsigned char*)src, srclen, (unsigned char*)tpbin->buf, &destlen2, NULL);
 	*destlen = destlen2;
 	switch (cresult) {
 	case LZO_E_OK:
@@ -116,7 +116,7 @@ lzo_decompress(Transformation *xform, st
  * Factory
  */
 Transformation
-*transformation_lzo_factory(int enc)
+*transformation_lzo_factory(UNUSED(int enc))
 {
 	Transformation *t = (Transformation *) malloc(sizeof (Transformation));
 
--- a/common/transformation_null.c
+++ b/common/transformation_null.c
@@ -7,7 +7,7 @@
  * Initialize
  */
 static int
-null_initialize(Transformation *xform, int enc)
+null_initialize(UNUSED(Transformation *xform), UNUSED(int enc))
 {
 	return 0;
 }
@@ -16,7 +16,7 @@ null_initialize(Transformation *xform, i
  * Shut down.
  */
 static int
-null_shutdown(Transformation *xform)
+null_shutdown(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -25,8 +25,8 @@ null_shutdown(Transformation *xform)
  * Handle fork.
  */
 static int
-null_startNewTape(Transformation *xform, struct tapebuf *tpbin,
-	unsigned long *destlen)
+null_startNewTape(UNUSED(Transformation *xform), UNUSED(struct tapebuf *tpbin),
+	UNUSED(unsigned long *destlen))
 {
 	return 0;
 }
@@ -35,7 +35,7 @@ null_startNewTape(Transformation *xform,
  * Start slave process.
  */
 static int
-null_startDiskIOProcess(Transformation *xform)
+null_startDiskIOProcess(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -44,7 +44,7 @@ null_startDiskIOProcess(Transformation *
  * End slave process.
  */
 static int
-null_endDiskIOProcess(Transformation *xform)
+null_endDiskIOProcess(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -53,8 +53,8 @@ null_endDiskIOProcess(Transformation *xf
  * Compress a buffer.
  */
 static int
-null_compress(Transformation *xform, struct tapebuf *tpbin, unsigned long *destlen,
-		const char *src, int srclen)
+null_compress(UNUSED(Transformation *xform), struct tapebuf *tpbin, unsigned long *destlen,
+	const char *src, int srclen)
 {
 	memcpy(tpbin->buf, src, srclen);
 	*destlen = srclen;
@@ -66,8 +66,8 @@ null_compress(Transformation *xform, str
  * Decompress a buffer.
  */
 static int
-null_decompress(Transformation *xform, struct tapebuf *tpbin, unsigned long *destlen,
-		const char *src, int srclen, char **reason)
+null_decompress(UNUSED(Transformation *xform), struct tapebuf *tpbin, unsigned long *destlen,
+	const char *src, int srclen, UNUSED(char **reason))
 {
 	memcpy(tpbin->buf, src, srclen);
 	*destlen = srclen;
@@ -81,7 +81,7 @@ null_decompress(Transformation *xform, s
 Transformation transformation_null =
 {
 	0,
-	NULL,
+	{0},
 	"null",
 	0,
 	&null_initialize,
--- a/common/transformation_ssl.c
+++ b/common/transformation_ssl.c
@@ -16,6 +16,12 @@
 
 #include "transformation.h"
 
+#ifdef HAVE_OPENSSL
+#define SSLONLY(x) x
+#else
+#define SSLONLY(x) UNUSED(x)
+#endif
+
 /*
  * IMPORTANT: this is an important piece of the puzzle for native
  * support of encrypted backups but Key management is much more
@@ -67,11 +73,9 @@
  * 3. how to pass keystore password(s), if doing restore?
  */
 static int
-ssl_initialize(Transformation *xform, int enc)
+ssl_initialize(UNUSED(Transformation *xform), UNUSED(int enc))
 {
 #ifdef HAVE_OPENSSL
-	int keylen;
-
 	OpenSSL_add_all_algorithms(); // see below */
 	OpenSSL_add_all_ciphers(); // see below */
 	OpenSSL_add_all_digests(); // see below */
@@ -115,7 +119,7 @@ ssl_initialize(Transformation *xform, in
  * we need to make sure we properly release it.
  */
 static int
-ssl_shutdown(Transformation *xform)
+ssl_shutdown(SSLONLY(Transformation *xform))
 {
 #ifdef HAVE_OPENSSL
 	OPENSSL_cleanse(xform->state.ssl.key, sizeof xform->state.ssl.key);
@@ -136,8 +140,8 @@ ssl_shutdown(Transformation *xform)
  * session key.
  */
 static int
-ssl_startNewTape(Transformation *xform, struct tapebuf *tpbin,
-	unsigned long *destlen)
+ssl_startNewTape(UNUSED(Transformation *xform), UNUSED(struct tapebuf *tpbin),
+	UNUSED(unsigned long *destlen))
 {
 #ifdef HAVE_OPENSSL
 	/* write new TS containing PKCS12 containing encrypted session key. */
@@ -151,7 +155,7 @@ ssl_startNewTape(Transformation *xform,
  * engine.
  */
 static int
-ssl_startDiskIOProcess(Transformation *xform)
+ssl_startDiskIOProcess(SSLONLY(Transformation *xform))
 {
 #ifdef HAVE_OPENSSL
 	mlock(xform, sizeof(Transformation));
@@ -177,7 +181,7 @@ ssl_startDiskIOProcess(Transformation *x
  * End of slave process. Clear encryption keys, etc.
  */
 static int
-ssl_endDiskIOProcess(Transformation *xform)
+ssl_endDiskIOProcess(SSLONLY(Transformation *xform))
 {
 #ifdef HAVE_OPENSSL
 	EVP_CIPHER_CTX_cleanup(xform->state.ssl.dataCtx);
@@ -260,8 +264,8 @@ generateIV(Transformation *xform, unsign
  *  - encrypted (plaintext . digest(plaintext))
  */
 static int
-ssl_compress(Transformation *xform, struct tapebuf *tpbin,
-	unsigned long *destlen, const char *src, int srclen)
+ssl_compress(SSLONLY(Transformation *xform), SSLONLY(struct tapebuf *tpbin),
+	SSLONLY(unsigned long *destlen), SSLONLY(const char *src), SSLONLY(int srclen))
 {
 #ifdef HAVE_OPENSSL
 	unsigned char salt[16], iv[EVP_MAX_MD_SIZE];
@@ -336,8 +340,9 @@ ssl_compress(Transformation *xform, stru
  *
  */
 static int
-ssl_decompress(Transformation *xform, struct tapebuf *tpbin,
-	unsigned long *destlen, const char *src, int srclen, char **reason)
+ssl_decompress(SSLONLY(Transformation *xform), SSLONLY(struct tapebuf *tpbin),
+	SSLONLY(unsigned long *destlen), SSLONLY(const char *src),
+	SSLONLY(int srclen), SSLONLY(char **reason))
 {
 #ifdef HAVE_OPENSSL
 	unsigned char salt[16], iv[EVP_MAX_MD_SIZE];
@@ -473,13 +478,17 @@ ssl_compress_ts_addr(char *state, struct
  * policy file.
  */
 Transformation
-*transformation_ssl_factory(int enc, int complvl, const char *ciphername, const char *digestname)
+*transformation_ssl_factory(int enc, SSLONLY(int complvl), SSLONLY(const char *ciphername), SSLONLY(const char *digestname))
 {
-	int keylen;
 	Transformation *t;
 
 	t = (Transformation *) malloc(sizeof (Transformation));
-	mlock(t, sizeof(Transformation));
+	if(!t)
+		return NULL;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+        mlock((const void*)t, sizeof(Transformation));
+#pragma GCC diagnostic pop
 
 #ifdef HAVE_OPENSSL
 	OpenSSL_add_all_ciphers();
--- a/common/transformation_zlib.c
+++ b/common/transformation_zlib.c
@@ -11,7 +11,7 @@
  * Initialize
  */
 static int
-zlib_initialize(Transformation *xform, int enc)
+zlib_initialize(UNUSED(Transformation *xform), UNUSED(int enc))
 {
 	return 0;
 }
@@ -20,7 +20,7 @@ zlib_initialize(Transformation *xform, i
  * Shut down.
  */
 static int
-zlib_shutdown(Transformation *xform)
+zlib_shutdown(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -29,8 +29,8 @@ zlib_shutdown(Transformation *xform)
  * Handle forks.
  */
 static int
-zlib_startNewTape(Transformation *xform, struct tapebuf *bin,
-	unsigned long *destlen)
+zlib_startNewTape(UNUSED(Transformation *xform), UNUSED(struct tapebuf *bin),
+	UNUSED(unsigned long *destlen))
 {
 	return 0;
 }
@@ -39,7 +39,7 @@ zlib_startNewTape(Transformation *xform,
  * Start slave process
  */
 static int
-zlib_startDiskIOProcess(Transformation *xform)
+zlib_startDiskIOProcess(UNUSED(Transformation *xform))
 {
 	return 0;
 }
@@ -66,12 +66,12 @@ struct req {
  * Compress a buffer.
  */
 static int
-zlib_compress(Transformation *xform, struct tapebuf *tpbin,
+zlib_compress(UNUSED(Transformation *xform), struct tapebuf *tpbin,
 		unsigned long *destlen, const char *src, int srclen)
 {
 #ifdef HAVE_ZLIB
 	int compresult;
-	compresult = compress2(tpbin->buf, destlen, src, srclen, xform->state.zlib.complvl);
+	compresult = compress2((unsigned char*)tpbin->buf, destlen, (const unsigned char*)src, srclen, xform->state.zlib.complvl);
 	return compresult == Z_OK ? 1 : 0;
 #else
 	return 1;
@@ -82,12 +82,12 @@ zlib_compress(Transformation *xform, str
  * Decompress a buffer.
  */
 static int
-zlib_decompress(Transformation *xform, struct tapebuf *tpbin,
+zlib_decompress(UNUSED(Transformation *xform), struct tapebuf *tpbin,
 	unsigned long *destlen, const char *src, int srclen, char **reason)
 {
 #ifdef HAVE_ZLIB
 	int cresult;
-	cresult = uncompress(tpbin->buf, destlen, src, srclen);
+	cresult = uncompress((unsigned char*)tpbin->buf, destlen, (const unsigned char*)src, srclen);
 	switch (cresult) {
 		case Z_OK:
 			*reason = "";
--- a/compat/include/bylabel.h
+++ b/compat/include/bylabel.h
@@ -20,6 +20,7 @@
 #ifdef HAVE_BLKID
 
 #include <blkid/blkid.h>
+#include <stdio.h>
 
 static inline const char * get_device_name(const char * item) {
 	return blkid_get_devname(NULL, item, NULL);
--- a/compat/lib/rmtflags.c
+++ b/compat/lib/rmtflags.c
@@ -167,7 +167,7 @@ rmtflags_tochar(int filemode)
 		strcpy(result, "O_RDWR");
 		break;
 	default:
-		strcat(result, "ERROR");
+		strcpy(result, "ERROR");
 	}
 	for (op = openflags; op->name; op++) {
 		if (op->value == O_RDONLY ||
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,9 @@ AC_SUBST([DATE], ["1 Jan 2021"])
 CPPFLAGS="${CPPFLAGS} -D_USE_BSD_SIGNAL "'-D_PATH_DUMPDATES=\"$(DUMPDATESPATH)\" -D_DUMP_VERSION=\"$(VERSION)\"'
 
 
+CFLAGS="${CFLAGS} -W -Wall"
+
+
 AC_DEFINE([LINUX_FORK_BUG], 1, [Workaround bad fork behavior on Linux])
 
 dnl Should these be options?
--- a/dump/dump.h
+++ b/dump/dump.h
@@ -36,6 +36,7 @@
  */
 
 #include <config.h>
+#include <sys/param.h>
 #include <protocols/dumprestore.h>
 #include "transformation.h"
 
@@ -118,10 +119,10 @@ extern Transformation *transformation;
 void	broadcast (const char *message);
 time_t	do_stats (void);
 void	lastdump (char arg);
-void	msg (const char *fmt, ...);
-void	msgtail (const char *fmt, ...);
+void	msg (const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+void	msgtail (const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
 int	query (const char *question);
-void	quit (const char *fmt, ...);
+void	quit (const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
 void	set_operators (void);
 #if defined(SIGINFO)
 void	statussig (int signo);
@@ -158,8 +159,9 @@ time_t	trewind (void);
 void	writerec (const void *dp, int isspcl);
 char	*mktimeest (time_t tnow);
 
-void 	Exit (int status);
-void	dumpabort (int signo);
+void 	Exit (int status) __attribute__ ((__noreturn__));
+
+void	dumpabort (int signo) __attribute__ ((__noreturn__));
 void	getfstab (void);
 
 const char *rawname (const char *cp);
--- a/dump/itime.c
+++ b/dump/itime.c
@@ -227,7 +227,7 @@ putdumptime(const char * disk)
 		(struct dumpdates *)calloc(1, sizeof (struct dumpdates));
 	nddates += 1;
   found:
-	(void) strncpy(dtwalk->dd_name, disk, sizeof (dtwalk->dd_name));
+	(void) strncpy(dtwalk->dd_name, disk, sizeof (dtwalk->dd_name) - 1);
 	dtwalk->dd_level = atoi(level);
 	dtwalk->dd_ddate = spcl.c_date;
 
@@ -244,21 +244,21 @@ putdumptime(const char * disk)
 static void
 dumprecout(FILE *file, struct dumpdates *what)
 {
-	char buf[26];
+	char buf[27] = {0};
 	struct tm *tms;
 
 	tms = localtime(&what->dd_ddate);
-	strncpy(buf, asctime(tms), sizeof(buf));
+	strncpy(buf, asctime(tms), sizeof(buf) - 1);
 	if (buf[24] != '\n' || buf[25] != '\0')
 		quit("asctime returned an unexpected string\n");
 	buf[24] = 0;
-	if (fprintf(file, "%s %d %s %c%2.2d%2.2d\n",
+	if (fprintf(file, "%s %d %s %c%2.2ld%2.2ld\n",
 		    what->dd_name,
 		    what->dd_level,
 		    buf,
 		    (tms->tm_gmtoff < 0 ? '-' : '+'),
-		    abs(tms->tm_gmtoff) / 3600,
-		    abs(tms->tm_gmtoff) % 3600 / 60) < 0)
+		    labs(tms->tm_gmtoff) / 3600,
+		    labs(tms->tm_gmtoff) % 3600 / 60) < 0)
 		quit("%s: %s\n", dumpdates, strerror(errno));
 }
 
--- a/dump/main.c
+++ b/dump/main.c
@@ -119,19 +119,19 @@ int	pipeout;	/* true => output to standa
 int	fifoout;	/* true => output to fifo */
 dump_ino_t curino;	/* current inumber; used globally */
 int	newtape;	/* new tape flag */
-int	density;	/* density in 0.1" units */
+int	density = 0;	/* density in 0.1" units */
 long long tapesize;	/* estimated tape size, blocks */
 long	tsize;		/* tape size in 0.1" units */
 long	asize;		/* number of 0.1" units written on current tape */
 int	etapes;		/* estimated number of tapes */
 int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
 int	unlimited;	/* if set, write to end of medium */
-int	compressed;	/* if set, dump is to be compressed */
-long long bytes_written;/* total bytes written to tape */
-long	uncomprblks;	/* uncompressed blocks written to tape */
-int	notify;		/* notify operator flag */
-int	blockswritten;	/* number of blocks written on current tape */
-int	tapeno;		/* current tape number */
+int	compressed = 0;	/* if set, dump is to be compressed */
+long long bytes_written = 0;/* total bytes written to tape */
+long	uncomprblks = 0;	/* uncompressed blocks written to tape */
+int	notify = 0;		/* notify operator flag */
+int	blockswritten = 0;	/* number of blocks written on current tape */
+int	tapeno = 0;		/* current tape number */
 time_t	tstart_writing;	/* when started writing the first tape block */
 time_t	tend_writing;	/* after writing the last tape block */
 #ifdef __linux__
@@ -151,10 +151,6 @@ int	nddates;		/* number of records (migh
 int	ddates_in;		/* we have read the increment file */
 struct	dumpdates **ddatev;	/* the arrayfied version */
 
-int	notify = 0;	/* notify operator flag */
-int	blockswritten = 0;	/* number of blocks written on current tape */
-int	tapeno = 0;	/* current tape number */
-int	density = 0;	/* density in bytes/0.1" " <- this is for hilit19 */
 int	ntrec = NTREC;	/* # blocks in each tape record */
 int	cartridge = 0;	/* Assume non-cartridge tape */
 #ifdef USE_QFA
@@ -166,9 +162,6 @@ long	dev_bsize = 1;	/* recalculated belo
 long	*blocksperfiles = NULL; /* output blocks per file(s) */
 char	*host = NULL;	/* remote host (if any) */
 int	sizest = 0;	/* return size estimate only */
-int	compressed = 0;	/* use zlib to compress the output, compress level 1-9 */
-long long bytes_written = 0; /* total bytes written */
-long	uncomprblks = 0;/* uncompressed blocks written */
 Transformation *transformation = &transformation_null;
 
 long smtc_errno;
@@ -536,8 +529,8 @@ main(int argc, char *argv[])
 		}
 	}
 
-	if (setuid(getuid()))
-		/* rmthost() is the only reason to be setuid */;
+	if (setuid(getuid())) {
+	} /* rmthost() is the only reason to be setuid */;
 	if (Apath && (Afile = open(Apath, O_WRONLY|O_CREAT|O_TRUNC,
 				   S_IRUSR | S_IWUSR | S_IRGRP |
 				   S_IWGRP | S_IROTH | S_IWOTH)) < 0) {
@@ -602,8 +595,8 @@ main(int argc, char *argv[])
 			exit(X_STARTUP);
 		}
 		disk = rawname(dt->mnt_fsname);
-		(void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN);
-		(void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN);
+		(void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN - 1);
+		(void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN - 1);
 	} else {
 #ifdef	__linux__
 #ifdef	HAVE_REALPATH
@@ -616,8 +609,8 @@ main(int argc, char *argv[])
 		 */
 		if ((dt = fstabsearch(pathname)) != NULL) {
 			disk = rawname(dt->mnt_fsname);
-			(void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN);
-			(void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN);
+			(void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN - 1);
+			(void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN - 1);
 		} else {
 			/*
 			 * The argument was not found in the fstab
@@ -625,16 +618,14 @@ main(int argc, char *argv[])
 			 */
 			dt = fstabsearchdir(pathname, directory);
 			if (dt != NULL) {
-				char name[MAXPATHLEN];
-				(void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN);
-				(void)snprintf(name, sizeof(name), "%s (dir %s)",
+				(void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN - 1);
+				(void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys), "%s (dir %s)",
 					      dt->mnt_dir, directory);
-				(void)strncpy(spcl.c_filesys, name, NAMELEN);
 				disk = rawname(dt->mnt_fsname);
 			} else {
-				(void)strncpy(spcl.c_dev, disk, NAMELEN);
+				(void)strncpy(spcl.c_dev, disk, NAMELEN - 1);
 				(void)strncpy(spcl.c_filesys, "an unlisted file system",
-				    NAMELEN);
+				    NAMELEN - 1);
 			}
 		}
 #else
@@ -734,7 +725,7 @@ main(int argc, char *argv[])
 	dev_bsize = DEV_BSIZE;
 	dev_bshift = ffs(dev_bsize) - 1;
 	if (dev_bsize != (1 << dev_bshift))
-		quit("dev_bsize (%d) is not a power of 2", dev_bsize);
+		quit("dev_bsize (%ld) is not a power of 2", dev_bsize);
 	tp_bshift = ffs(TP_BSIZE) - 1;
 	if (TP_BSIZE != (1 << tp_bshift))
 		quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
@@ -954,7 +945,7 @@ main(int argc, char *argv[])
 		if (dp->di_nlink == 0 || dp->di_dtime != 0)
 			continue;
 		if (vflag)
-			msg("dumping directory inode %lu\n", ino);
+			msg("dumping directory inode %u\n", ino);
 		(void)dumpdirino(dp, ino);
 #else
 		(void)dumpino(dp, ino);
@@ -983,9 +974,9 @@ main(int argc, char *argv[])
 #endif
 		if (vflag) {
 			if (mflag && TSTINO(ino, metainomap))
-				msg("dumping regular inode %lu (meta only)\n", ino);
+				msg("dumping regular inode %u (meta only)\n", ino);
 			else
-				msg("dumping regular inode %lu\n", ino);
+				msg("dumping regular inode %u\n", ino);
 		}
 		(void)dumpino(dp, ino, mflag && TSTINO(ino, metainomap));
 	}
@@ -1012,10 +1003,10 @@ main(int argc, char *argv[])
 	tnow = trewind();
 
 	if (pipeout || fifoout)
-		msg("%ld blocks (%.2fMB)\n", spcl.c_tapea,
+		msg("%d blocks (%.2fMB)\n", spcl.c_tapea,
 			((double)spcl.c_tapea * TP_BSIZE / 1048576));
 	else
-		msg("%ld blocks (%.2fMB) on %d volume(s)\n",
+		msg("%d blocks (%.2fMB) on %d volume(s)\n",
 		    spcl.c_tapea,
 		    ((double)spcl.c_tapea * TP_BSIZE / 1048576),
 		    spcl.c_volume);
@@ -1024,7 +1015,7 @@ main(int argc, char *argv[])
 	if (tend_writing - tstart_writing == 0)
 		msg("finished in less than a second\n");
 	else
-		msg("finished in %d seconds, throughput %d kBytes/sec\n",
+		msg("finished in %ld seconds, throughput %ld kBytes/sec\n",
 		    tend_writing - tstart_writing,
 		    spcl.c_tapea / (tend_writing - tstart_writing));
 
@@ -1037,7 +1028,7 @@ main(int argc, char *argv[])
 	if (compressed) {
 		long tapekb = bytes_written / 1024;
 		double rate = .0005 + (double) spcl.c_tapea / tapekb;
-		msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
+		msg("Wrote %dkB uncompressed, %ldkB compressed, %1.3f:1\n",
 			spcl.c_tapea, tapekb, rate);
 	}
 
@@ -1047,8 +1038,6 @@ main(int argc, char *argv[])
 	broadcast("DUMP IS DONE!\7\7\n");
 	msg("DUMP IS DONE\n");
 	Exit(X_FINOK);
-	/* NOTREACHED */
-	return 0;	/* gcc - shut up */
 }
 
 static void
--- a/dump/optr.c
+++ b/dump/optr.c
@@ -271,7 +271,6 @@ broadcast(const char *message)
 	}
 	(void) fclose(f_utmp);
 	Exit(0);	/* the wait in this same routine will catch this */
-	/* NOTREACHED */
 }
 
 static void
--- a/dump/tape.c
+++ b/dump/tape.c
@@ -286,7 +286,7 @@ tperror(int errnum)
 		quit("Cannot recover\n");
 		/* NOTREACHED */
 	}
-	msg("write error %d blocks into volume %d: %s\n",
+	msg("write error %ld blocks into volume %d: %s\n",
 	    blocksthisvol, tapeno, strerror(errnum));
 	broadcast("DUMP WRITE ERROR!\n");
 	if (query("Do you want to rewrite this volume?")) {
@@ -324,19 +324,19 @@ do_stats(void)
 	blocks = spcl.c_tapea - tapea_volume;
 	msg("Volume %d completed at: %s", tapeno, ctime(&tnow));
 	if (! compressed)
-		msg("Volume %d %ld blocks (%.2fMB)\n", tapeno,
+		msg("Volume %d %d blocks (%.2fMB)\n", tapeno,
 			blocks, ((double)blocks * TP_BSIZE / 1048576));
 	if (ttaken > 0) {
 		long volkb = (bytes_written - tapea_bytes) / 1024;
 		long txfrate = volkb / ttaken;
-		msg("Volume %d took %d:%02d:%02d\n", tapeno,
+		msg("Volume %d took %ld:%02ld:%02ld\n", tapeno,
 			ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60);
 		msg("Volume %d transfer rate: %ld kB/s\n", tapeno,
 			txfrate);
 		xferrate += txfrate;
 		if (compressed) {
 			double rate = .0005 + (double) blocks / (double) volkb;
-			msg("Volume %d %ldkB uncompressed, %ldkB compressed,"
+			msg("Volume %d %dkB uncompressed, %ldkB compressed,"
 				" %1.3f:1\n",
 				tapeno, blocks, volkb, rate);
 		}
@@ -479,7 +479,7 @@ flushtape(void)
 	blocksthisvol += ntrec;
 	if (!pipeout && !unlimited) {
 		if (blocksperfiles && blocksperfiles[blocksperfiles_current]) {
-			if ( compressed ? (bytes_written - tapea_bytes + SLAVES * (writesize + sizeof(struct tapebuf))) >= (((long long)blocksperfiles[blocksperfiles_current]) * 1024)
+			if ( compressed ? (bytes_written - tapea_bytes + SLAVES * (writesize + sizeof(struct tapebuf))) >= ((blocksperfiles[blocksperfiles_current]) * 1024ULL)
 					: blocksthisvol >= blocksperfiles[blocksperfiles_current] ) {
 				close_rewind();
 				startnewtape(0);
@@ -944,7 +944,7 @@ restore_check_point:
 			spcl.c_flags |= DR_COMPRESSED;
 		writeheader((dump_ino_t)slp->inode);
 		spcl.c_flags &=~ DR_NEWHEADER;
-		msg("Volume %d started with block %ld at: %s", tapeno,
+		msg("Volume %d started with block %d at: %s", tapeno,
 		    spcl.c_tapea, ctime(&tstart_volume));
 		if (tapeno > 1)
 			msg("Volume %d begins with blocks from inode %d\n",
@@ -1207,14 +1207,14 @@ doslave(int cmd,
 	 * Get list of blocks to dump, read the blocks into tape buffer
 	 */
 	while ((nread = dump_atomic_read( cmd, (char *)slp->req, reqsiz)) == reqsiz) {
-		struct req *p = slp->req;
-
 		/* wait for previous slave to finish reading */
 		if (sigsetjmp(jmpbuf1, 1) == 0) {
 			ready1 = 1;
 			if (!caught1)
 				sigsuspend(&set);
 		}
+		struct req *p = slp->req;
+
 		ready1 = 0;
 		caught1 = 0;
 
--- a/dump/traverse.c
+++ b/dump/traverse.c
@@ -877,7 +877,6 @@ static void iterate_extents(struct block
 	struct ext2fs_extent extent;
 	int op = EXT2_EXTENT_ROOT;
 	errcode_t errcode;
-	int ret = 0;
 
 	errcode = ext2fs_extent_open(fs, ino, &handle);
 	if (errcode) {
@@ -1023,6 +1022,7 @@ dumpino(struct dinode *dp, dump_ino_t in
 		}
 #endif
 		/* fall through */
+		__attribute__ ((fallthrough));
 
 #ifndef	__linux__
 	case S_IFDIR:
@@ -1056,7 +1056,7 @@ dumpino(struct dinode *dp, dump_ino_t in
 		iterate_extents(&bc, fs, (ext2_ino_t)ino);
 	} else if (dp->di_mode & S_IFREG && dp->di_flags & EXT4_INLINE_DATA_FL) {
 		/* Untested - Can we ever get here? */
-		msg("Unexpectedly got EXT4_INLINE_DATA_FL while dumping inode %lu\n", ino);
+		msg("Unexpectedly got EXT4_INLINE_DATA_FL while dumping inode %u\n", ino);
 	} else {
 		ext2fs_block_iterate3(fs, (ext2_ino_t)ino, BLOCK_FLAG_DATA_ONLY, NULL, dumponeblock, (void *)&bc);
 	}
@@ -1256,7 +1256,7 @@ dumpdirino(struct dinode *dp, dump_ino_t
 	case S_IFDIR:
 		if (dir_size > 0)
 			break;
-		msg("Warning: size of directory inode #%d is <= 0 (%d)!\n",
+		msg("Warning: size of directory inode #%d is <= 0 (%ld)!\n",
 			ino, dir_size);
 		return;
 
@@ -1424,7 +1424,6 @@ mkchecksum(union u_spcl *tmpspcl)
 void
 writeheader(dump_ino_t ino)
 {
-	char *state; /* need to have some place to put this! */
 	spcl.c_inumber = ino;
 	spcl.c_magic = NFS_MAGIC;
 	mkchecksum((union u_spcl *)&spcl);
@@ -1490,9 +1489,9 @@ loop:
 						((off_t)blkno << dev_bshift))
 #endif
 		msg("bread: lseek fails\n");
-	if ((cnt = read(diskfd, buf, size)) == size)
+	if ((cnt = read(diskfd, buf, size)) == (long)size)
 		return;
-	if (blkno + (size / dev_bsize) > fsbtodb(sblock, sblock->fs_size)) {
+	if (blkno + (size / dev_bsize) > (unsigned long long)fsbtodb(sblock, sblock->fs_size)) {
 		/*
 		 * Trying to read the final fragment.
 		 *
@@ -1507,14 +1506,14 @@ loop:
 		goto loop;
 	}
 	if (cnt == -1)
-		msg("read error from %s: %s: [block %d, ext2blk %d]: count=%d\n",
+		msg("read error from %s: %s: [block %lld, ext2blk %d]: count=%lu\n",
 			disk, strerror(errno), blkno,
 			dbtofsb(sblock, blkno), size);
 	else
-		msg("short read error from %s: [block %d, ext2blk %d]: count=%d, got=%d\n",
+		msg("short read error from %s: [block %lld, ext2blk %d]: count=%lu, got=%d\n",
 			disk, blkno, dbtofsb(sblock, blkno), size, cnt);
 	if (breademax && ++breaderrors > breademax) {
-		msg("More than %d block read errors from %d\n",
+		msg("More than %d block read errors from %s\n",
 			breademax, disk);
 		broadcast("DUMP IS AILING!\n");
 		msg("This is an unrecoverable error.\n");
@@ -1528,7 +1527,7 @@ loop:
 	 * Zero buffer, then try to read each sector of buffer separately.
 	 */
 	memset(buf, 0, size);
-	for (i = 0; i < size; i += dev_bsize, buf += dev_bsize, blkno++) {
+	for (i = 0; i < (long)size; i += dev_bsize, buf += dev_bsize, blkno++) {
 #ifdef	__linux__
 		if (ext2fs_llseek(diskfd, (blkno << dev_bshift), 0) !=
 				(blkno << dev_bshift))
@@ -1540,12 +1539,12 @@ loop:
 		if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize)
 			continue;
 		if (cnt == -1) {
-			msg("read error from %s: %s: [sector %d, ext2blk %d]: count=%d\n",
+			msg("read error from %s: %s: [sector %lld, ext2blk %d]: count=%ld\n",
 				disk, strerror(errno), blkno,
 				dbtofsb(sblock, blkno), dev_bsize);
 			continue;
 		}
-		msg("short read error from %s: [sector %d, ext2blk %d]: count=%d, got=%d\n",
+		msg("short read error from %s: [sector %lld, ext2blk %d]: count=%ld, got=%d\n",
 			disk, blkno, dbtofsb(sblock, blkno), dev_bsize, cnt);
 	}
 }
--- a/restore/extern.h
+++ b/restore/extern.h
@@ -35,7 +35,12 @@
  * SUCH DAMAGE.
  */
 
+#ifndef _EXTERN_H_
+#define _EXTERN_H_
+
 #include <config.h>
+#include <protocols/dumprestore.h>
+#include "restore.h"
 #ifdef DUMP_MACOSX
 #include "darwin.h"
 #endif
@@ -156,3 +161,5 @@ int	xattr_compare (char *, char *);
 int	xattr_extract (char *, char *);
 int xattr_count_file (char *);
 int xattr_count (char *, int *);
+
+#endif /* !_EXTERN_H_ */
--- a/restore/interactive.c
+++ b/restore/interactive.c
@@ -222,6 +222,7 @@ loop:
 	case 'h':
 		if (strncmp(cmd, "help", strlen(cmd)) != 0)
 			goto bad;
+		__attribute__((fallthrough));
 	case '?':
 		fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
 			"Available commands are:\n",
@@ -438,7 +439,7 @@ getnext:
 	ap->argcnt = ap->glob.gl_pathc;
 
 retnext:
-	strncpy(name, ap->glob.gl_pathv[ap->glob.gl_pathc - ap->argcnt], size);
+	strncpy(name, ap->glob.gl_pathv[ap->glob.gl_pathc - ap->argcnt], size - 1);
 	name[size - 1] = '\0';
 	if (--ap->argcnt == 0) {
 		ap->freeglob = 0;
@@ -863,14 +864,14 @@ rl_gets (char *dir)
 	completion_curdir[MAXPATHLEN - 1] = '\0';
 
 	if (pflag) {
-		sz = 6 + strlen(__progname) + strlen(spcl.c_filesys) + strlen((completion_curdir + 1 ? completion_curdir + 1 : "/"));
+		sz = 6 + strlen(__progname) + strlen(spcl.c_filesys) + strlen((completion_curdir[1] ? completion_curdir + 1 : "/"));
 		prompt = (char *)malloc(sz);
 		if (!prompt)
 			return NULL;
 		snprintf(prompt, sz, "%s:%s:%s > ",
 			__progname,
 			spcl.c_filesys,
-			(completion_curdir + 1 ? completion_curdir + 1 : "/"));
+			(completion_curdir[1] ? completion_curdir + 1 : "/"));
 	}
 	else {
 		sz = 4 + strlen(__progname);
@@ -932,7 +933,7 @@ filename_generator(const char *text, int
 	RST_DIR *dirp;
 	struct direct *dp;
 	static int entries;
-	char pname[MAXPATHLEN];
+	char pname[MAXPATHLEN*2+2];
 	char fname[MAXPATHLEN];
 	char *slash;
 	char ppname[MAXPATHLEN];
@@ -953,16 +954,16 @@ filename_generator(const char *text, int
 			ppname[MAXPATHLEN - 1] = '\0';
 			ppname[idx] = '\0';
 			if (text[0] == '/')
-				snprintf(pname, MAXPATHLEN, ".%s", ppname);
+				snprintf(pname, sizeof(pname), ".%s", ppname);
 			else
-				snprintf(pname, MAXPATHLEN, "%s/%s", completion_curdir, ppname);
+				snprintf(pname, sizeof(pname), "%s/%s", completion_curdir, ppname);
 			strncpy(fname, ppname + idx + 1, MAXPATHLEN);
 			ppname[idx] = '/';
 			ppname[idx + 1] = '\0';
 		}
 		else {
 			strncpy(pname, completion_curdir, MAXPATHLEN);
-			strncpy(fname, text, MAXPATHLEN);
+			strncpy(fname, text, MAXPATHLEN - 1);
 			ppname[0] = '\0';
 		}
 		pname[MAXPATHLEN - 1] = '\0';
--- a/restore/main.c
+++ b/restore/main.c
@@ -159,7 +159,7 @@ main(int argc, char *argv[])
 	createtapeposflag = 0;
 #endif /* USE_QFA */
 #ifdef TRANSSELINUX			/*GAN6May06 SELinux MLS */
-	char transselinuxopt;
+	char transselinuxopt = 0;
 #endif
 
 	/* Temp files should *not* be readable.  We set permissions later. */
@@ -385,7 +385,9 @@ main(int argc, char *argv[])
 		char wd[MAXPATHLEN], fullpathinput[MAXPATHLEN];
 		if (!getcwd(wd, MAXPATHLEN))
 			err(1, "can't get current directory");
-		snprintf(fullpathinput, MAXPATHLEN, "%s/%s", wd, inputdev);
+		size_t len = snprintf(fullpathinput, MAXPATHLEN, "%s/%s", wd, inputdev);
+		if (len >= MAXPATHLEN)
+			err(1, "%s/%s is more than %d characters", wd, inputdev, MAXPATHLEN);
 		fullpathinput[MAXPATHLEN - 1] = '\0';
 		setinput(fullpathinput);
 	}
--- a/restore/restore.c
+++ b/restore/restore.c
@@ -894,7 +894,9 @@ createfiles(void)
 #ifdef USE_QFA
 	long tnum, tmpcnt;
 	long long tpos, curtpos = 0;
+#ifdef DEBUG_QFA
 	time_t tistart, tiend, titaken;
+#endif
 	int		volChg;
 #endif
 
@@ -956,7 +958,9 @@ createfiles(void)
 		 */
 		next = lowerbnd(curfile.ino);
 #ifdef USE_QFA
+#ifdef DEBUG_QFA
 		tistart = time(NULL);
+#endif
 		if (tapeposflag) {
 			/* get tape position for inode */
 			(void)Inode2Tapepos(next, &tnum, &tpos, 0);
@@ -1021,9 +1025,9 @@ createfiles(void)
 			skipdirs();
 		} while (volno == curvol + 1);
 #ifdef USE_QFA
+#ifdef DEBUG_QFA
 		tiend = time(NULL);
 		titaken = tiend - tistart;
-#ifdef DEBUG_QFA
 		if (titaken / 60 > 0)
 			msg("%ld reads took %d:%02d:%02d\n",
 				tmpcnt, titaken / 3600,
--- a/restore/restore.h
+++ b/restore/restore.h
@@ -40,6 +40,9 @@
  * SUCH DAMAGE.
  */
 
+#ifndef _RESTORE_H_
+#define _RESTORE_H_
+
 #include <config.h>
 #include <protocols/dumprestore.h>
 /*
@@ -205,3 +208,5 @@ extern char	*transselinuxarg;
 // 60 is the combined size of the direct and indirect block pointers in the inode.
 #define INLINE_DATA_MAX_INODE_SIZE 60
 extern char inline_data[INLINE_DATA_MAX_INODE_SIZE + XATTR_MAXSIZE];
+
+#endif /* !_RESTORE_H_ */
--- a/restore/tape.c
+++ b/restore/tape.c
@@ -233,6 +233,7 @@ setinput(char *source)
 		}
 	} else
 #endif
+	{
 	if (strcmp(source, "-") == 0) {
 		/*
 		 * Since input is coming from a pipe we must establish
@@ -247,6 +248,7 @@ setinput(char *source)
 		}
 		pipein++;
 	}
+	}
 	/* no longer need or want root privileges */
 	if (setuid(getuid()))
 		err(1, "cannot setuid");
@@ -324,10 +326,12 @@ setup(void)
 		mt = rmtopen(temptape, O_RDONLY);
 	else
 #endif
+	{
 	if (pipein)
 		mt = 0;
 	else
 		mt = open(temptape, O_RDONLY, 0);
+	}
 	if (mt < 0)
 		err(1, "%s", temptape);
 	if (!Afile) {
@@ -402,7 +406,7 @@ setup(void)
 	if (spcl.c_volume != 1)
 		errx(1, "Tape is not volume 1 of the dump");
 	if (gethead(&spcl) == FAIL) {
-		Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread);
+		Dprintf(stdout, "header read failed at %ld blocks\n", blksread);
 		panic("no header after volume mark!\n");
 	}
 	readingmaps = 1;
@@ -558,7 +562,9 @@ again:
 	Afile = NULL;
 
 	if (Mflag) {
-		snprintf(magtape, MAXPATHLEN, "%s%03ld", magtapeprefix, newvol);
+		size_t len = snprintf(magtape, MAXPATHLEN, "%s%03ld", magtapeprefix, newvol);
+		if (len >= MAXPATHLEN)
+			err(1, "%s%03ld is more than %d characters", magtapeprefix, newvol, MAXPATHLEN);
 		magtape[MAXPATHLEN - 1] = '\0';
 	}
 	if (bot_script && !haderror) {
@@ -633,7 +639,7 @@ gethdr:
 	FLUSHTAPEBUF();
 	findtapeblksize();
 	if (gethead(&tmpbuf) == FAIL) {
-		Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread);
+		Dprintf(stdout, "header read failed at %ld blocks\n", blksread);
 		fprintf(stderr, "tape is not dump tape\n");
 		volno = 0;
 		haderror = 1;
@@ -1106,10 +1112,9 @@ extractattr(char *path)
 		case EXT_XATTR: {
 			char xattr[XATTR_MAXSIZE];
 
-			if (readxattr(xattr) == GOOD) {
+			if (readxattr(xattr) == GOOD)
 				xattr_extract(path, xattr);
-				break;
-			}
+			break;
 		}
 		default:
 			msg("unexpected inode extension %ld, skipping\n", spcl.c_extattributes);
@@ -1412,14 +1417,14 @@ loop:
 	}
 	while (gethead(&spcl) != GOOD) {
 		fprintf(stderr, "Incorrect block for %s at %ld blocks\n",
-			curfile.name, (long)blksread);
+			curfile.name, blksread);
 	}
 	if (size > 0) {
 		if (spcl.c_type == TS_ADDR)
 			goto loop;
 		Dprintf(stdout,
 			"Missing address (header) block for %s at %ld blocks\n",
-			curfile.name, (long)blksread);
+			curfile.name, blksread);
 	}
 	if (curblk > 0) {
 		(*fill)((char *)buf, (size_t)((curblk * TP_BSIZE) + size));
@@ -2396,7 +2401,7 @@ decompress_tapebuf(struct tapebuf *tpbin
 			errx(1,"This restore version doesn't support zlib decompression");
 #else
 			cresult = uncompress(comprbuf, &worklen,
-					     tpbin->buf, blocklen);
+					     (const unsigned char*)tpbin->buf, blocklen);
 			output = comprbuf;
 			switch (cresult) {
 				case Z_OK:
@@ -2457,7 +2462,7 @@ decompress_tapebuf(struct tapebuf *tpbin
 			errx(1,"This restore version doesn't support lzo decompression");
 #else
 			lzo_uint worklen2 = worklen;
-			cresult = lzo1x_decompress(tpbin->buf, blocklen, comprbuf,
+			cresult = lzo1x_decompress((const unsigned char*)tpbin->buf, blocklen, comprbuf,
 				&worklen2, NULL);
 			worklen = worklen2;
 			output = comprbuf;
@@ -3016,11 +3021,11 @@ findinode(struct s_spcl *header)
 
 		case TS_TAPE:
 			panic("unexpected tape header\n");
-			/* NOTREACHED */
+			exit(1);
 
 		default:
 			panic("unknown tape header type %d\n", spcl.c_type);
-			/* NOTREACHED */
+			exit(1);
 
 		}
 	} while (header->c_type == TS_ADDR);
@@ -3413,9 +3418,9 @@ ReReadInodeFromTape(dump_ino_t theino)
 	tpblksread = spcl.c_tapea + spcl.c_volume;
 #ifdef DEBUG_QFA
 	fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
-	fprintf(stderr, "DEBUG: bufsize %ld\n", bufsize);
-	fprintf(stderr, "DEBUG: ntrec %ld\n", ntrec);
-	fprintf(stderr, "DEBUG: tapea %d\n", spcl.c_tapea);
+	fprintf(stderr, "DEBUG: bufsize %d\n", bufsize);
+	fprintf(stderr, "DEBUG: ntrec %d\n", ntrec);
+	fprintf(stderr, "DEBUG: tapea %u\n", spcl.c_tapea);
 	fprintf(stderr, "DEBUG: tpblksread %ld\n", tpblksread);
 #endif
 	findinode(&spcl);
--- a/restore/xattr.c
+++ b/restore/xattr.c
@@ -209,7 +209,7 @@ posix_acl_to_xattr(const struct posix_ac
 	real_size = posix_acl_xattr_size(acl->a_count);
 	if (!buffer)
 		return real_size;
-	if (real_size > size) {
+	if (real_size > (long)size) {
 		fprintf(stderr, "ACL: not enough space to convert (%d %d)\n", real_size, (int)size);
 		return -1;
 	}
@@ -219,7 +219,7 @@ posix_acl_to_xattr(const struct posix_ac
 	swabst("1i", (u_char *)ext_acl);
 #endif
 
-	for (n=0; n < acl->a_count; n++, ext_entry++) {
+	for (n=0; n < (long)acl->a_count; n++, ext_entry++) {
 		ext_entry->e_tag  = acl->a_entries[n].e_tag;
 		ext_entry->e_perm = acl->a_entries[n].e_perm;
 		ext_entry->e_id   = acl->a_entries[n].e_id;
@@ -313,7 +313,7 @@ fail:
  */
 
 static int
-xattr_cb_list(char *name, char *value, int valuelen, int isSELinux, void *private)
+xattr_cb_list(char *name, char *value, int valuelen, int isSELinux, UNUSED(void *private))
 {
   if (strcmp(name, "system.data") == 0) {
 		return GOOD;
--- a/rmt/rmt.c
+++ b/rmt/rmt.c
@@ -304,7 +304,7 @@ top:
 		cp = record;
 #endif
 		(void)sprintf(resp, "A%lld\n", (long long)rval);
-		if (write(1, resp, strlen(resp)) != strlen(resp))
+		if (write(1, resp, strlen(resp)) != (long)strlen(resp))
 			goto ioerror;
 		if (write(1, cp, rval) != rval)
 			goto ioerror;
@@ -471,14 +471,14 @@ top:
 			mtget.mt_fileno = swaplong(mtget.mt_fileno);
 			mtget.mt_blkno = swaplong(mtget.mt_blkno);
 			(void)sprintf(resp, "A%lld\n", (long long)rval);
-			if (write(1, resp, strlen(resp)) != strlen(resp))
+			if (write(1, resp, strlen(resp)) != (long)strlen(resp))
 				goto ioerror;
 			if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget))
 				goto ioerror;
 		  } else {
 		  	rval = sizeof (mtget);
 			(void)sprintf(resp, "A%lld\n", (long long)rval);
-			if (write(1, resp, strlen(resp)) != strlen(resp))
+			if (write(1, resp, strlen(resp)) != (long)strlen(resp))
 				goto ioerror;
 			if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget))
 				goto ioerror;
@@ -546,7 +546,7 @@ top:
 respond:
 	DEBUG1("rmtd: A %lld\n", (long long)rval);
 	(void)sprintf(resp, "A%lld\n", (long long)rval);
-	if (write(1, resp, strlen(resp)) != strlen(resp))
+	if (write(1, resp, strlen(resp)) != (long)strlen(resp))
 		goto ioerror;
 	goto top;
 ioerror:
@@ -594,7 +594,7 @@ error(int num)
 
 	DEBUG2("rmtd: E %d (%s)\n", num, strerror(num));
 	(void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num));
-	if (write(1, resp, strlen(resp)) != strlen(resp))
+	if (write(1, resp, strlen(resp)) != (long)strlen(resp))
 		DEBUG("rmtd: write error\n");
 }
 
--- a/common/indexer_test.c
+++ b/common/indexer_test.c
@@ -131,7 +131,7 @@ dump_inode(Indexer *indexer, struct stat
  *
  */
 int
-dump_walk(Indexer *indexer, const char *root, int first)
+dump_walk(Indexer *indexer, const char *root, UNUSED(int first))
 {
 	DIR *dirp;
 	struct dirent *dp;
@@ -185,9 +185,6 @@ dump_walk(Indexer *indexer, const char *
 void
 test_indexer(Indexer *indexer, const char *filename, const char *path)
 {
-	struct direct dp;
-	struct stat buf;
-
 #ifdef HAVE_UUID
 	test_fs.super = &test_super;
 	uuid_generate_time((unsigned char *)&test_fs.super->s_uuid);
