From d45f6fe61395dcf009c7e2806de793e79fdb60b6 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Wed, 25 Jul 2018 00:40:30 +0000
Subject: [PATCH] Enable GCC printf-format checking for more printf-style
 functions and fix the resulting warnings.

---
 src/sbbs3/atcodes.cpp  |  2 +-
 src/sbbs3/execmisc.cpp | 12 +++++-----
 src/sbbs3/getstr.cpp   |  4 ++--
 src/sbbs3/listfile.cpp |  2 +-
 src/sbbs3/pack_qwk.cpp |  4 ++--
 src/sbbs3/readmsgs.cpp | 50 +++++++++++++++++++++---------------------
 src/sbbs3/sbbs.h       | 18 ++++++++++++---
 src/sbbs3/str.cpp      |  2 +-
 src/sbbs3/writemsg.cpp |  8 +++----
 9 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp
index 59f43ef825..2cd6fae9dd 100644
--- a/src/sbbs3/atcodes.cpp
+++ b/src/sbbs3/atcodes.cpp
@@ -101,7 +101,7 @@ int sbbs_t::show_atcode(const char *instr)
 	} else if(zero_padded) {
 		int vlen = strlen(cp);
 		if(vlen < disp_len)
-			bprintf("%-.*s%s", disp_len - strlen(cp), "0000000000", cp);
+			bprintf("%-.*s%s", (int)(disp_len - strlen(cp)), "0000000000", cp);
 		else
 			bprintf("%.*s", disp_len, cp);
 	} else
diff --git a/src/sbbs3/execmisc.cpp b/src/sbbs3/execmisc.cpp
index 496911b572..8362cf7484 100644
--- a/src/sbbs3/execmisc.cpp
+++ b/src/sbbs3/execmisc.cpp
@@ -85,7 +85,7 @@ int sbbs_t::exec_misc(csi_t* csi, char *path)
 					if(!pp || !*pp) {
 						lp=getintvar(csi,*(int32_t *)csi->ip);
 						if(lp)
-							bprintf("%ld",*lp); 
+							bprintf("%d",*lp);
 					}
 					else
 						putmsg(cmdstr(*pp,path,csi->str,buf)
@@ -107,25 +107,25 @@ int sbbs_t::exec_misc(csi_t* csi, char *path)
 					free(p);
 					return(0);
 				case SHOW_VARS:
-					bprintf("shell     str=(%08lX) %s\r\n"
+					bprintf("shell     str=(%p) %s\r\n"
 						,csi->str,csi->str);
 					for(i=0;i<csi->str_vars;i++)
-						bprintf("local  str[%d]=(%08lX) (%08lX) %s\r\n"
+						bprintf("local  str[%d]=(%08X) (%p) %s\r\n"
 							,i,csi->str_var_name[i]
 							,csi->str_var[i]
 							,csi->str_var[i]);
 					for(i=0;i<csi->int_vars;i++)
-						bprintf("local  int[%d]=(%08lX) (%08lX) %ld\r\n"
+						bprintf("local  int[%d]=(%08X) (%08X) %d\r\n"
 							,i,csi->int_var_name[i]
 							,csi->int_var[i]
 							,csi->int_var[i]);
 					for(i=0;i<global_str_vars;i++)
-						bprintf("global str[%d]=(%08lX) (%08lX) %s\r\n"
+						bprintf("global str[%d]=(%08X) (%p) %s\r\n"
 							,i,global_str_var_name[i]
 							,global_str_var[i]
 							,global_str_var[i]);
 					for(i=0;i<global_int_vars;i++)
-						bprintf("global int[%d]=(%08lX) (%08lX) %ld\r\n"
+						bprintf("global int[%d]=(%08X) (%08X) %d\r\n"
 							,i,global_int_var_name[i]
 							,global_int_var[i]
 							,global_int_var[i]);
diff --git a/src/sbbs3/getstr.cpp b/src/sbbs3/getstr.cpp
index 0b598d9263..cc18acd0c8 100644
--- a/src/sbbs3/getstr.cpp
+++ b/src/sbbs3/getstr.cpp
@@ -153,7 +153,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode)
 						l++;
 					for(x=l;x>i;x--)
 						str1[x]=str1[x-1];
-					column+=rprintf("%.*s",l-i,str1+i);
+					column+=rprintf("%.*s",(int)(l-i),str1+i);
 					cursor_left(l-i);
 #if 0
 					if(i==maxlen-1)
@@ -526,7 +526,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode)
 							l++;
 						for(x=l;x>i;x--)
 							str1[x]=str1[x-1];
-						column+=rprintf("%.*s",l-i,str1+i);
+						column+=rprintf("%.*s",(int)(l-i),str1+i);
 						cursor_left(l-i);
 #if 0
 						if(i==maxlen-1) {
diff --git a/src/sbbs3/listfile.cpp b/src/sbbs3/listfile.cpp
index bc844751e6..7341e558d0 100644
--- a/src/sbbs3/listfile.cpp
+++ b/src/sbbs3/listfile.cpp
@@ -530,7 +530,7 @@ bool sbbs_t::listfile(const char *fname, const char *buf, uint dirnum
 			attr(cfg.color[clr_filedesc]^HIGH);
 			bprintf("%.*s",i,str+j);
 			attr(cfg.color[clr_filedesc]);
-			bprintf("%.*s",strlen(str)-(j+i),str+j+i); 
+			bprintf("%.*s",(int)(strlen(str)-(j+i)),str+j+i); 
 		}
 		else
 			bputs(str);
diff --git a/src/sbbs3/pack_qwk.cpp b/src/sbbs3/pack_qwk.cpp
index 46397a7193..614a5870af 100644
--- a/src/sbbs3/pack_qwk.cpp
+++ b/src/sbbs3/pack_qwk.cpp
@@ -382,7 +382,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
 
 			for(u=0;u<mailmsgs;u++) {
 				if(online == ON_REMOTE)
-					bprintf("\b\b\b\b\b\b\b\b\b\b\b\b%4lu of %-4lu"
+					bprintf("\b\b\b\b\b\b\b\b\b\b\b\b%4u of %-4u"
 						,u+1,mailmsgs);
 
 				memset(&msg,0,sizeof(msg));
@@ -509,7 +509,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
 
 				for(u=0;u<posts && !msgabort();u++) {
 					if(online == ON_REMOTE)
-						bprintf("\b\b\b\b\b%-5lu",u+1);
+						bprintf("\b\b\b\b\b%-5u",u+1);
 
 					subscan[usrsub[i][j]].ptr=post[u].idx.number;	/* set ptr */
 					subscan[usrsub[i][j]].last=post[u].idx.number; /* set last read */
diff --git a/src/sbbs3/readmsgs.cpp b/src/sbbs3/readmsgs.cpp
index f7598a3b33..b5c9dbd4e3 100644
--- a/src/sbbs3/readmsgs.cpp
+++ b/src/sbbs3/readmsgs.cpp
@@ -136,53 +136,53 @@ void sbbs_t::msghdr(smbmsg_t* msg)
 	}
 
 	/* fixed fields */
-	bprintf("%-16.16s %08lX %04hX %.24s %s\r\n","when_written"	
+	bprintf("%-16.16s %08X %04hX %.24s %s\r\n","when_written"	
 		,msg->hdr.when_written.time, msg->hdr.when_written.zone
 		,timestr(msg->hdr.when_written.time)
 		,smb_zonestr(msg->hdr.when_written.zone,NULL));
-	bprintf("%-16.16s %08lX %04hX %.24s %s\r\n","when_imported"	
+	bprintf("%-16.16s %08X %04hX %.24s %s\r\n","when_imported"	
 		,msg->hdr.when_imported.time, msg->hdr.when_imported.zone
 		,timestr(msg->hdr.when_imported.time)
 		,smb_zonestr(msg->hdr.when_imported.zone,NULL));
-	bprintf("%-16.16s %04Xh\r\n","type"				,msg->hdr.type);
-	bprintf("%-16.16s %04Xh\r\n","version"			,msg->hdr.version);
-	bprintf("%-16.16s %04Xh\r\n","attr"				,msg->hdr.attr);
-	bprintf("%-16.16s %08lXh\r\n","auxattr"			,msg->hdr.auxattr);
-	bprintf("%-16.16s %08lXh\r\n","netattr"			,msg->hdr.netattr);
-	bprintf("%-16.16s %06lXh\r\n","header offset"	,msg->idx.offset);
-	bprintf("%-16.16s %u\r\n"	 ,"header length"	,msg->hdr.length);
-	bprintf("%-16.16s %ld\r\n"	 ,"number"			,msg->hdr.number);
+	bprintf("%-16.16s %04Xh\r\n"	,"type"			,msg->hdr.type);
+	bprintf("%-16.16s %04Xh\r\n"	,"version"		,msg->hdr.version);
+	bprintf("%-16.16s %04Xh\r\n"	,"attr"			,msg->hdr.attr);
+	bprintf("%-16.16s %08Xh\r\n"	,"auxattr"		,msg->hdr.auxattr);
+	bprintf("%-16.16s %08Xh\r\n"	,"netattr"		,msg->hdr.netattr);
+	bprintf("%-16.16s %06Xh\r\n"	,"header offset"	,msg->idx.offset);
+	bprintf("%-16.16s %u\r\n"	,"header length"	,msg->hdr.length);
+	bprintf("%-16.16s %d\r\n"	,"number"		,msg->hdr.number);
 
 	/* optional fixed fields */
 	if(msg->hdr.thread_id)
-		bprintf("%-16.16s %ld\r\n"	,"thread_id"		,msg->hdr.thread_id);
+		bprintf("%-16.16s %d\r\n"	,"thread_id"		,msg->hdr.thread_id);
 	if(msg->hdr.thread_back)
-		bprintf("%-16.16s %ld\r\n"	,"thread_back"		,msg->hdr.thread_back);
+		bprintf("%-16.16s %d\r\n"	,"thread_back"		,msg->hdr.thread_back);
 	if(msg->hdr.thread_next)
-		bprintf("%-16.16s %ld\r\n"	,"thread_next"		,msg->hdr.thread_next);
+		bprintf("%-16.16s %d\r\n"	,"thread_next"		,msg->hdr.thread_next);
 	if(msg->hdr.thread_first)
-		bprintf("%-16.16s %ld\r\n"	,"thread_first"		,msg->hdr.thread_first);
+		bprintf("%-16.16s %d\r\n"	,"thread_first"		,msg->hdr.thread_first);
 	if(msg->hdr.delivery_attempts)
-		bprintf("%-16.16s %hu\r\n"	,"delivery_attempts",msg->hdr.delivery_attempts);
+		bprintf("%-16.16s %hu\r\n"	,"delivery_attempts"	,msg->hdr.delivery_attempts);
 	if(msg->hdr.times_downloaded)
-		bprintf("%-16.16s %lu\r\n"	,"times_downloaded"	,msg->hdr.times_downloaded);
+		bprintf("%-16.16s %u\r\n"	,"times_downloaded"	,msg->hdr.times_downloaded);
 	if(msg->hdr.last_downloaded)
 		bprintf("%-16.16s %s\r\n"	,"last_downloaded"	,timestr(msg->hdr.last_downloaded));
 	if(msg->hdr.votes)
-		bprintf("%-16.16s %hu\r\n"	,"votes"			,msg->hdr.votes);
+		bprintf("%-16.16s %hu\r\n"	,"votes"		,msg->hdr.votes);
 
 	/* convenience integers */
 	if(msg->expiration)
-		bprintf("%-16.16s %s\r\n"	,"expiration"	
+		bprintf("%-16.16s %s\r\n"	,"expiration"
 			,timestr(msg->expiration));
 	if(msg->priority)
-		bprintf("%-16.16s %lu\r\n"	,"priority"			,msg->priority);
+		bprintf("%-16.16s %u\r\n"	,"priority"			,msg->priority);
 	if(msg->cost)
-		bprintf("%-16.16s %lu\r\n"	,"cost"				,msg->cost);
+		bprintf("%-16.16s %u\r\n"	,"cost"				,msg->cost);
 
-	bprintf("%-16.16s %06lXh\r\n"	,"data offset"		,msg->hdr.offset);
+	bprintf("%-16.16s %06Xh\r\n"	,"data offset"		,msg->hdr.offset);
 	for(i=0;i<msg->hdr.total_dfields;i++)
-		bprintf("data field[%u]    %s, offset %lu, length %lu\r\n"
+		bprintf("data field[%u]    %s, offset %u, length %u\r\n"
 				,i
 				,smb_dfieldtype(msg->dfield[i].type)
 				,msg->dfield[i].offset
@@ -461,8 +461,8 @@ void sbbs_t::show_thread(uint32_t msgnum, post_t* post, unsigned curmsg, int thr
 //		,msg.hdr.number
 		,(unsigned)i == curmsg ? '>' : ':');
 	bprintf("\1w%-*.*s\1g%c\1g%c \1w%s\r\n"
-		,cols-column-12
-		,cols-column-12
+		,(int)(cols-column-12)
+		,(int)(cols-column-12)
 		,msg.hdr.attr&MSG_ANONYMOUS && !sub_op(smb.subnum)
 			? text[Anonymous] : msg.from
 		,(unsigned)i == curmsg ? '<' : ' '
@@ -735,7 +735,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
 				break;
 			}
 			bprintf("\1n\1l\1h\1bThread\1n\1b: \1h\1c");
-			bprintf("%-.*s\r\n", cols-(column+1), msg.subj);
+			bprintf("%-.*s\r\n", (int)(cols-(column+1)), msg.subj);
 			show_thread(first, post, smb.curmsg);
 			subscan[subnum].last = post[smb.curmsg].idx.number;
 		}
diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h
index 61bcf7c4d4..2107a006be 100644
--- a/src/sbbs3/sbbs.h
+++ b/src/sbbs3/sbbs.h
@@ -686,8 +686,16 @@ public:
 	/* con_out.cpp */
 	int		bputs(const char *str);					/* BBS puts function */
 	int		rputs(const char *str, size_t len=0);	/* BBS raw puts function */
-	int		bprintf(const char *fmt, ...);			/* BBS printf function */
-	int		rprintf(const char *fmt, ...);			/* BBS raw printf function */
+	int		bprintf(const char *fmt, ...)			/* BBS printf function */
+#if defined(__GNUC__)   // Catch printf-format errors
+    __attribute__ ((format (printf, 2, 3)));		// 1 is 'this'
+#endif
+	;
+	int		rprintf(const char *fmt, ...)			/* BBS raw printf function */
+#if defined(__GNUC__)   // Catch printf-format errors
+    __attribute__ ((format (printf, 2, 3)));		// 1 is 'this'
+#endif
+	;
 	void	backspace(void);				/* Output a destructive backspace via outchar */
 	void	outchar(char ch);				/* Output a char - check echo and emu.  */
 	void	center(char *str);
@@ -811,7 +819,11 @@ public:
 
 	/* main.cpp */
 	int		lputs(int level, const char* str);
-	int		lprintf(int level, const char *fmt, ...);
+	int		lprintf(int level, const char *fmt, ...)
+#if defined(__GNUC__)   // Catch printf-format errors
+    __attribute__ ((format (printf, 3, 4)));		// 1 is 'this'
+#endif
+	;
 	void	printstatslog(uint node);
 	ulong	logonstats(void);
 	void	logoffstats(void);
diff --git a/src/sbbs3/str.cpp b/src/sbbs3/str.cpp
index 5dde5a9ac3..ae3d1f1221 100644
--- a/src/sbbs3/str.cpp
+++ b/src/sbbs3/str.cpp
@@ -1067,7 +1067,7 @@ bool sbbs_t::spy(uint i /* node_num */)
 		return(false);
 	}
 	if(spy_socket[i-1]!=INVALID_SOCKET) {
-		bprintf("Node %d already being spied (%lx)\r\n",i,spy_socket[i-1]);
+		bprintf("Node %d already being spied (%x)\r\n",i,spy_socket[i-1]);
 		return(false);
 	}
 	bprintf("*** Synchronet Remote Spy on Node %d: Ctrl-C to Abort ***"
diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index c85c4dcac5..89523eaa80 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -827,14 +827,14 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
 		if(sys_status&SS_ABORT) {
 			if(line==lines)
 				free(str[line]);
-			continue; 
+			continue;
 		}
 		if(strin[0]=='/' && strlen(strin)<8) {
 			if(!stricmp(strin,"/DEBUG") && SYSOP) {
 				if(line==lines)
 					free(str[line]);
-				bprintf("\r\nline=%d lines=%d rows=%d\r\n",line,lines,rows);
-				continue; 
+				bprintf("\r\nline=%d lines=%d rows=%ld\r\n",line,lines,rows);
+				continue;
 			}
 			else if(!stricmp(strin,"/ABT")) {
 				if(line==lines) 		/* delete a line */
@@ -842,7 +842,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
 				for(i=0;i<lines;i++)
 					free(str[i]);
 				free(str);
-				return(0); 
+				return(0);
 			}
 			else if(toupper(strin[1])=='D') {
 				if(line==lines)         /* delete a line */
-- 
GitLab