From d4734bc65fa0b3836dfa8d6a949704fe912d2349 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Thu, 11 Apr 2019 01:19:00 +0000
Subject: [PATCH] Address new-found safe_snprintf() usage problems/warnings
 (thanks GCC!).

---
 src/sbbs3/atcodes.cpp  | 54 +++++++++++++++++++++---------------------
 src/sbbs3/mailsrvr.c   | 10 ++++----
 src/sbbs3/msg_id.c     |  4 ++--
 src/sbbs3/prntfile.cpp |  2 +-
 src/sbbs3/readmsgs.cpp |  2 +-
 src/sbbs3/smbutil.c    |  4 ++--
 src/sbbs3/useredit.cpp |  2 +-
 src/sbbs3/websrvr.c    |  4 ++--
 src/sbbs3/writemsg.cpp |  2 +-
 9 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp
index 49eb0c161f..5c971a5861 100644
--- a/src/sbbs3/atcodes.cpp
+++ b/src/sbbs3/atcodes.cpp
@@ -312,7 +312,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 
 	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
 		getstats(&cfg,0,&stats);
-		safe_snprintf(str,maxlen,"%lu",stats.logons);
+		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
 		return(str);
 	}
 
@@ -574,7 +574,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 	}
 
 	if(!strcmp(sp,"BYTELIMIT")) {
-		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]);
+		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
 		return(str);
 	}
 
@@ -957,27 +957,27 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 		getstats(&cfg,0,&stats);
 		sp+=6;
 		if(!strcmp(sp,"LOGONS"))
-			safe_snprintf(str,maxlen,"%lu",stats.logons);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
 		else if(!strcmp(sp,"LTODAY"))
-			safe_snprintf(str,maxlen,"%lu",stats.ltoday);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.ltoday);
 		else if(!strcmp(sp,"TIMEON"))
-			safe_snprintf(str,maxlen,"%lu",stats.timeon);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.timeon);
 		else if(!strcmp(sp,"TTODAY"))
-			safe_snprintf(str,maxlen,"%lu",stats.ttoday);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.ttoday);
 		else if(!strcmp(sp,"ULS"))
-			safe_snprintf(str,maxlen,"%lu",stats.uls);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.uls);
 		else if(!strcmp(sp,"ULB"))
-			safe_snprintf(str,maxlen,"%lu",stats.ulb);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.ulb);
 		else if(!strcmp(sp,"DLS"))
-			safe_snprintf(str,maxlen,"%lu",stats.dls);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.dls);
 		else if(!strcmp(sp,"DLB"))
-			safe_snprintf(str,maxlen,"%lu",stats.dlb);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.dlb);
 		else if(!strcmp(sp,"PTODAY"))
-			safe_snprintf(str,maxlen,"%lu",stats.ptoday);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.ptoday);
 		else if(!strcmp(sp,"ETODAY"))
-			safe_snprintf(str,maxlen,"%lu",stats.etoday);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.etoday);
 		else if(!strcmp(sp,"FTODAY"))
-			safe_snprintf(str,maxlen,"%lu",stats.ftoday);
+			safe_snprintf(str,maxlen,"%lu", (ulong)stats.ftoday);
 		else if(!strcmp(sp,"NUSERS"))
 			safe_snprintf(str,maxlen,"%u",stats.nusers);
 		return(str);
@@ -1119,23 +1119,23 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 	if(!strcmp(sp,"MSG_REPLY_ID") && current_msg!=NULL)
 		return(current_msg->reply_id==NULL ? nulstr : current_msg->reply_id);
 	if(!strcmp(sp,"MSG_NUM") && current_msg!=NULL) {
-		safe_snprintf(str,maxlen,"%lu",current_msg->hdr.number);
+		safe_snprintf(str,maxlen,"%lu", (ulong)current_msg->hdr.number);
 		return(str);
 	}
 	if(!strcmp(sp,"MSG_SCORE") && current_msg!=NULL) {
-		safe_snprintf(str, maxlen, "%ld", current_msg->upvotes - current_msg->downvotes);
+		safe_snprintf(str, maxlen, "%ld", (long)(current_msg->upvotes - current_msg->downvotes));
 		return(str);
 	}
 	if(!strcmp(sp,"MSG_UPVOTES") && current_msg!=NULL) {
-		safe_snprintf(str, maxlen, "%lu", current_msg->upvotes);
+		safe_snprintf(str, maxlen, "%lu", (ulong)current_msg->upvotes);
 		return(str);
 	}
 	if(!strcmp(sp,"MSG_DOWNVOTES") && current_msg!=NULL) {
-		safe_snprintf(str, maxlen, "%lu", current_msg->downvotes);
+		safe_snprintf(str, maxlen, "%lu", (ulong)current_msg->downvotes);
 		return(str);
 	}
 	if(!strcmp(sp,"MSG_TOTAL_VOTES") && current_msg!=NULL) {
-		safe_snprintf(str, maxlen, "%lu", current_msg->total_votes);
+		safe_snprintf(str, maxlen, "%lu", (ulong)current_msg->total_votes);
 		return(str);
 	}
 	if(!strcmp(sp,"MSG_VOTED"))
@@ -1205,23 +1205,23 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_MSGS")) {
-		safe_snprintf(str,maxlen,"%ld",smb.msgs);
+		safe_snprintf(str,maxlen,"%lu", (ulong)smb.msgs);
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_CURMSG")) {
-		safe_snprintf(str,maxlen,"%ld",smb.curmsg+1);
+		safe_snprintf(str,maxlen,"%lu", (ulong)(smb.curmsg+1));
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_LAST_MSG")) {
-		safe_snprintf(str,maxlen,"%lu",smb.status.last_msg);
+		safe_snprintf(str,maxlen,"%lu", (ulong)smb.status.last_msg);
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_MAX_MSGS")) {
-		safe_snprintf(str,maxlen,"%lu",smb.status.max_msgs);
+		safe_snprintf(str,maxlen,"%lu", (ulong)smb.status.max_msgs);
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_MAX_CRCS")) {
-		safe_snprintf(str,maxlen,"%lu",smb.status.max_crcs);
+		safe_snprintf(str,maxlen,"%lu", (ulong)smb.status.max_crcs);
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_MAX_AGE")) {
@@ -1229,7 +1229,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 		return(str);
 	}
 	if(!strcmp(sp,"SMB_TOTAL_MSGS")) {
-		safe_snprintf(str,maxlen,"%lu",smb.status.total_msgs);
+		safe_snprintf(str,maxlen,"%lu", (ulong)smb.status.total_msgs);
 		return(str);
 	}
 
@@ -1274,11 +1274,11 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 		if(strcmp(sp, "FILE_UPLOADER") == 0)
 			return current_file->uler;
 		if(strcmp(sp, "FILE_SIZE") == 0) {
-			safe_snprintf(str, maxlen, "%lu", current_file->size);
+			safe_snprintf(str, maxlen, "%ld", (long)current_file->size);
 			return str;
 		}
 		if(strcmp(sp, "FILE_CREDITS") == 0) {
-			safe_snprintf(str, maxlen, "%lu", current_file->cdt);
+			safe_snprintf(str, maxlen, "%lu", (ulong)current_file->cdt);
 			return str;
 		}
 		if(strcmp(sp, "FILE_TIME") == 0)
@@ -1295,7 +1295,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 			return datestr(current_file->datedled);
 
 		if(strcmp(sp, "FILE_TIMES_DLED") == 0) {
-			safe_snprintf(str, maxlen, "%lu", current_file->timesdled);
+			safe_snprintf(str, maxlen, "%d", current_file->timesdled);
 			return str;
 		}
 	}
diff --git a/src/sbbs3/mailsrvr.c b/src/sbbs3/mailsrvr.c
index d96a37c3d4..d204078261 100644
--- a/src/sbbs3/mailsrvr.c
+++ b/src/sbbs3/mailsrvr.c
@@ -1696,11 +1696,11 @@ static ulong rblchk(SOCKET sock, const char* prot, union xp_sockaddr *addr, cons
 	switch(addr->addr.sa_family) {
 		case AF_INET:
 			mail_addr=ntohl(addr->in.sin_addr.s_addr);
-			safe_snprintf(name,sizeof(name),"%ld.%ld.%ld.%ld.%.128s"
-				,mail_addr&0xff
-				,(mail_addr>>8)&0xff
-				,(mail_addr>>16)&0xff
-				,(mail_addr>>24)&0xff
+			safe_snprintf(name,sizeof(name),"%lu.%lu.%lu.%lu.%.128s"
+				,(ulong)(mail_addr&0xff)
+				,(ulong)(mail_addr>>8)&0xff
+				,(ulong)(mail_addr>>16)&0xff
+				,(ulong)(mail_addr>>24)&0xff
 				,rbl_addr
 				);
 			break;
diff --git a/src/sbbs3/msg_id.c b/src/sbbs3/msg_id.c
index f966092b43..aefd3b43d3 100644
--- a/src/sbbs3/msg_id.c
+++ b/src/sbbs3/msg_id.c
@@ -35,7 +35,7 @@
 
 #include "sbbs.h"
 
-static uint32_t msg_number(smbmsg_t* msg)
+static ulong msg_number(smbmsg_t* msg)
 {
 	if(msg->idx.number)
 		return(msg->idx.number);
@@ -56,7 +56,7 @@ uint32_t get_new_msg_number(smb_t* smb)
 	return smb->status.last_msg + 1;
 }
 
-static uint32_t msg_time(smbmsg_t* msg)
+static ulong msg_time(smbmsg_t* msg)
 {
 	if(msg->idx.time)
 		return(msg->idx.time);
diff --git a/src/sbbs3/prntfile.cpp b/src/sbbs3/prntfile.cpp
index b48ec48e6b..c25cfa5199 100644
--- a/src/sbbs3/prntfile.cpp
+++ b/src/sbbs3/prntfile.cpp
@@ -249,7 +249,7 @@ bool sbbs_t::menu_exists(const char *code, const char* ext, char* path)
 		backslash(menu_dir);
 		SAFEPRINTF3(prefix, "%smenu/%s%s", cfg.text_dir, menu_dir, code);
 	}
-	safe_snprintf(path, MAX_PATH, "%s.%ucol.%s", prefix, cols, ext);
+	safe_snprintf(path, MAX_PATH, "%s.%lucol.%s", prefix, cols, ext);
 	if(fexistcase(path))
 		return true;
 	safe_snprintf(path, MAX_PATH, "%s.%s", prefix, ext);
diff --git a/src/sbbs3/readmsgs.cpp b/src/sbbs3/readmsgs.cpp
index a9558a4ef0..ceb83f2c25 100644
--- a/src/sbbs3/readmsgs.cpp
+++ b/src/sbbs3/readmsgs.cpp
@@ -518,7 +518,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
 		char cmdline[256];
 
 		scanposts_inside = true;
-		safe_snprintf(cmdline, sizeof(cmdline), "%s %s %u %s", cfg.scanposts_mod, cfg.sub[subnum]->code, mode, find);
+		safe_snprintf(cmdline, sizeof(cmdline), "%s %s %ld %s", cfg.scanposts_mod, cfg.sub[subnum]->code, mode, find);
 		i=exec_bin(cmdline, &main_csi);
 		scanposts_inside = false;
 		return i;
diff --git a/src/sbbs3/smbutil.c b/src/sbbs3/smbutil.c
index 586a41d2fb..5bb87dd730 100644
--- a/src/sbbs3/smbutil.c
+++ b/src/sbbs3/smbutil.c
@@ -196,8 +196,8 @@ char* gen_msgid(smb_t* smb, smbmsg_t* msg, char* msgid, size_t maxlen)
 	);
 	safe_snprintf(msgid, maxlen
 		,"<%08lX.%lu.%s@%s>"
-		,msg->hdr.when_imported.time
-		,smb->status.last_msg + 1
+		,(ulong)msg->hdr.when_imported.time
+		,(ulong)smb->status.last_msg + 1
 		,getfname(smb->file)
 		,host);
 	return msgid;
diff --git a/src/sbbs3/useredit.cpp b/src/sbbs3/useredit.cpp
index 3a9d7bc20a..0b967af6f8 100644
--- a/src/sbbs3/useredit.cpp
+++ b/src/sbbs3/useredit.cpp
@@ -812,7 +812,7 @@ void sbbs_t::maindflts(user_t* user)
 		bprintf(text[UserDefaultsHdr],user->alias,user->number);
 		long term = (user == &useron) ? term_supports() : user->misc;
 		if(term&PETSCII)
-			safe_snprintf(str,sizeof(str),"%sPETSCII %u columns"
+			safe_snprintf(str,sizeof(str),"%sPETSCII %lu columns"
 							,user->misc&AUTOTERM ? "Auto Detect ":nulstr
 							,cols);
 		else
diff --git a/src/sbbs3/websrvr.c b/src/sbbs3/websrvr.c
index 6596541a51..45bdb18184 100644
--- a/src/sbbs3/websrvr.c
+++ b/src/sbbs3/websrvr.c
@@ -1350,7 +1350,7 @@ static BOOL send_headers(http_session_t *session, const char *status, int chunke
 				}
 				else  {
 					if((session->req.range_start || session->req.range_end) && atoi(status_line)==206) {
-						safe_snprintf(header,sizeof(header),"%s: %d",get_header(HEAD_LENGTH),session->req.range_end-session->req.range_start+1);
+						safe_snprintf(header,sizeof(header),"%s: %ld",get_header(HEAD_LENGTH),session->req.range_end-session->req.range_start+1);
 						safecat(headers,header,MAX_HEADERS_SIZE);
 					}
 					else {
@@ -1374,7 +1374,7 @@ static BOOL send_headers(http_session_t *session, const char *status, int chunke
 			if(session->req.range_start || session->req.range_end) {
 				switch(atoi(status_line)) {
 					case 206:	/* Partial reply */
-						safe_snprintf(header,sizeof(header),"%s: bytes %d-%d/%d",get_header(HEAD_CONTENT_RANGE),session->req.range_start,session->req.range_end,stats.st_size);
+						safe_snprintf(header,sizeof(header),"%s: bytes %ld-%ld/%ld",get_header(HEAD_CONTENT_RANGE),session->req.range_start,session->req.range_end,stats.st_size);
 						safecat(headers,header,MAX_HEADERS_SIZE);
 						break;
 					default:
diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index e2de158202..ffd060a4ee 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -970,7 +970,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
 				if(j) j--;  /* start from line j */
 				while(str[j] != NULL && !msgabort()) {
 					if(linenums) { /* line numbers */
-						SAFEPRINTF3(tmp,"%3d: %-.*s",j+1,cols-6,str[j]);
+						SAFEPRINTF3(tmp,"%3d: %-.*s", j+1, (int)(cols-6), str[j]);
 						putmsg(tmp,P_SAVEATR|P_NOATCODES); 
 					}
 					else
-- 
GitLab