From 5588d2414f3b6921b78647e31093504b8fdcdf1c Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Fri, 6 Apr 2018 02:42:38 +0000 Subject: [PATCH] Use GCC-printf-style format/arg checking to find and fix problems with ::lprintf() usage. --- src/sbbs3/js_cryptcon.c | 2 +- src/sbbs3/jsexec.c | 2 +- src/sbbs3/main.cpp | 24 ++++++++++++------------ src/sbbs3/pack_rep.cpp | 4 ++-- src/sbbs3/readtext.c | 2 +- src/sbbs3/sbbs.h | 12 ++++++++++-- src/sbbs3/un_qwk.cpp | 2 +- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/sbbs3/js_cryptcon.c b/src/sbbs3/js_cryptcon.c index 4887da295f..2165aeed9b 100644 --- a/src/sbbs3/js_cryptcon.c +++ b/src/sbbs3/js_cryptcon.c @@ -614,7 +614,7 @@ js_create_signature(JSContext *cx, uintN argc, jsval *arglist) } signature = malloc(len); if (signature == NULL) { - lprintf(LOG_ERR, "Unable to allocate %lu bytes\n", len); + lprintf(LOG_ERR, "Unable to allocate %u bytes\n", len); JS_RESUMEREQUEST(cx, rc); return JS_FALSE; } diff --git a/src/sbbs3/jsexec.c b/src/sbbs3/jsexec.c index 3a0c44ac76..4c821d6ee0 100644 --- a/src/sbbs3/jsexec.c +++ b/src/sbbs3/jsexec.c @@ -1014,7 +1014,7 @@ long js_exec(const char *fname, char** args) strcpy(line,"\n"); /* To keep line count correct */ len=strlen(line); if((js_buf=realloc(js_buf,js_buflen+len))==NULL) { - lprintf(LOG_ERR,"!Error allocating %u bytes of memory" + lprintf(LOG_ERR,"!Error allocating %lu bytes of memory" ,js_buflen+len); if(fp!=stdin) fclose(fp); diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index dd33b25918..91e13ff184 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -1591,7 +1591,7 @@ static BYTE* telnet_interpret(sbbs_t* sbbs, BYTE* inbuf, int inlen, } else if(option==TELNET_NEGOTIATE_WINDOW_SIZE) { long cols = (sbbs->telnet_cmd[3]<<8) | sbbs->telnet_cmd[4]; long rows = (sbbs->telnet_cmd[5]<<8) | sbbs->telnet_cmd[6]; - lprintf(LOG_DEBUG,"Node %d %s telnet window size: %ux%u" + lprintf(LOG_DEBUG,"Node %d %s telnet window size: %ldx%ld" ,sbbs->cfg.node_num ,sbbs->telnet_mode&TELNET_MODE_GATE ? "passed-through" : "received" ,cols @@ -2025,7 +2025,7 @@ void input_thread(void *arg) else wrbuf=telnet_interpret(sbbs, inbuf, rd, telbuf, wr); if(wr > (int)sizeof(telbuf)) - lprintf(LOG_ERR,"!TELBUF OVERFLOW (%d>%d)",wr,sizeof(telbuf)); + lprintf(LOG_ERR,"!TELBUF OVERFLOW (%d>%lu)",wr,sizeof(telbuf)); /* First level Ctrl-C checking */ if(!(sbbs->cfg.ctrlkey_passthru&(1<<CTRL_C)) @@ -2034,10 +2034,10 @@ void input_thread(void *arg) && sbbs->telnet_remote_option[TELNET_BINARY_TX]!=TELNET_WILL && memchr(wrbuf, CTRL_C, wr)) { if(RingBufFull(&sbbs->inbuf)) - lprintf(LOG_DEBUG,"Node %d Ctrl-C hit with %lu bytes in input buffer" + lprintf(LOG_DEBUG,"Node %d Ctrl-C hit with %u bytes in input buffer" ,sbbs->cfg.node_num,RingBufFull(&sbbs->inbuf)); if(RingBufFull(&sbbs->outbuf)) - lprintf(LOG_DEBUG,"Node %d Ctrl-C hit with %lu bytes in output buffer" + lprintf(LOG_DEBUG,"Node %d Ctrl-C hit with %u bytes in output buffer" ,sbbs->cfg.node_num,RingBufFull(&sbbs->outbuf)); sbbs->sys_status|=SS_ABORT; RingBufReInit(&sbbs->inbuf); /* Purge input buffer */ @@ -2180,7 +2180,7 @@ void passthru_output_thread(void* arg) else wrbuf=telnet_interpret(sbbs, inbuf, rd, telbuf, wr); if(wr > (int)sizeof(telbuf)) - lprintf(LOG_ERR,"!TELBUF OVERFLOW (%d>%d)",wr,sizeof(telbuf)); + lprintf(LOG_ERR,"!TELBUF OVERFLOW (%d>%lu)",wr,sizeof(telbuf)); /* * TODO: This should check for writability etc. @@ -2492,7 +2492,7 @@ void output_thread(void* arg) } if(i!=(int)(buftop-bufbot)) { - lprintf(LOG_WARNING,"%s !Short socket send (%u instead of %u)" + lprintf(LOG_WARNING,"%s !Short socket send (%u instead of %lu)" ,node, i ,buftop-bufbot); short_sends++; } @@ -3036,7 +3036,7 @@ void event_thread(void* arg) || sbbs->cfg.event[i]->node>last_node) { eprintf(LOG_INFO,"Waiting for node %d to run timed event: %s" ,sbbs->cfg.event[i]->node, event_code); - eprintf(LOG_DEBUG,"%s event last run: %s (0x%08lx)" + eprintf(LOG_DEBUG,"%s event last run: %s (0x%08x)" ,event_code ,timestr(&sbbs->cfg, sbbs->cfg.event[i]->last, str) ,sbbs->cfg.event[i]->last); @@ -3232,7 +3232,7 @@ sbbs_t::sbbs_t(ushort node_num, union xp_sockaddr *addr, size_t addr_len, const else SAFECOPY(nodestr,name); - ::lprintf(LOG_DEBUG,"%s constructor using socket %d (settings=%lx)" + ::lprintf(LOG_DEBUG,"%s constructor using socket %d (settings=%x)" ,nodestr, sd, global_cfg->node_misc); startup = ::startup; // Convert from global to class member @@ -4372,7 +4372,7 @@ void node_thread(void* arg) if(startup->login_attempt.throttle && (login_attempts=loginAttempts(startup->login_attempt_list, &sbbs->client_addr)) > 1) { - lprintf(LOG_DEBUG,"Node %d Throttling suspicious connection from: %s (%u login attempts)" + lprintf(LOG_DEBUG,"Node %d Throttling suspicious connection from: %s (%lu login attempts)" ,sbbs->cfg.node_num, sbbs->client_ipaddr, login_attempts); mswait(login_attempts*startup->login_attempt.throttle); } @@ -4933,7 +4933,7 @@ void DLLCALL bbs_thread(void* arg) #pragma warn -8066 /* Disable "Unreachable code" warning */ #endif if(sizeof(node_t)!=SIZEOF_NODE_T) { - lprintf(LOG_CRIT,"!COMPILER ERROR: sizeof(node_t)=%d instead of %d" + lprintf(LOG_CRIT,"!COMPILER ERROR: sizeof(node_t)=%lu instead of %d" ,sizeof(node_t),SIZEOF_NODE_T); cleanup(1); return; @@ -4954,7 +4954,7 @@ void DLLCALL bbs_thread(void* arg) } t=time(NULL); - lprintf(LOG_INFO,"Initializing on %.24s with options: %lx" + lprintf(LOG_INFO,"Initializing on %.24s with options: %x" ,ctime_r(&t,str),startup->options); if(chdir(startup->ctrl_dir)!=0) @@ -5393,7 +5393,7 @@ NO_SSH: if(banned || sbbs->trashcan(host_ip,"ip")) { if(banned) { char ban_duration[128]; - lprintf(LOG_NOTICE, "%04d !TEMPORARY BAN of %s (%u login attempts%s%s) - remaining: %s" + lprintf(LOG_NOTICE, "%04d !TEMPORARY BAN of %s (%lu login attempts%s%s) - remaining: %s" ,client_socket, host_ip, attempted.count-attempted.dupes ,attempted.user[0] ? ", last: " : "", attempted.user, seconds_to_str(banned, ban_duration)); } else diff --git a/src/sbbs3/pack_rep.cpp b/src/sbbs3/pack_rep.cpp index 7a5327e9e6..7b50193ef7 100644 --- a/src/sbbs3/pack_rep.cpp +++ b/src/sbbs3/pack_rep.cpp @@ -158,7 +158,7 @@ bool sbbs_t::pack_rep(uint hubnum) smb_freemsgmem(&msg); YIELD(); /* yield */ } - eprintf(LOG_INFO,"Packed %d NetMail messages",packedmail); + eprintf(LOG_INFO,"Packed %ld NetMail messages",packedmail); } smb_close(&smb); /* Close the e-mail */ if(mailmsgs) @@ -353,7 +353,7 @@ bool sbbs_t::pack_rep(uint hubnum) smb_close(&smb); if(mailmsgs) free(mail); - eprintf(LOG_INFO,"Deleted %d sent NetMail messages",deleted); + eprintf(LOG_INFO,"Deleted %ld sent NetMail messages",deleted); } return(true); diff --git a/src/sbbs3/readtext.c b/src/sbbs3/readtext.c index 0d2bc3a07f..3454b53e24 100644 --- a/src/sbbs3/readtext.c +++ b/src/sbbs3/readtext.c @@ -23,7 +23,7 @@ char *readtext(long *line,FILE *stream,long dflt) p=strrchr(buf,'"'); if(!p) { if(line) - lprintf(LOG_WARNING,"No quotation marks in line %d of text.dat",*line); + lprintf(LOG_WARNING,"No quotation marks in line %ld of text.dat",*line); goto use_default; } if(*(p+1)=='\\') /* merge multiple lines */ diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 014269a62b..a7585f3b77 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -1357,8 +1357,16 @@ char* prep_code(char *str, const char* prefix); /* main.c */ int lputs(int level, const char *); /* log output */ - int lprintf(int level, const char *fmt, ...); /* log output */ - int eprintf(int level, const char *fmt, ...); /* event log */ + int lprintf(int level, const char *fmt, ...) /* log output */ +#if defined(__GNUC__) // Catch printf-format errors + __attribute__ ((format (printf, 2, 3))); +#endif + ; + int eprintf(int level, const char *fmt, ...) /* event log */ +#if defined(__GNUC__) // Catch printf-format errors + __attribute__ ((format (printf, 2, 3))); +#endif + ; void call_socket_open_callback(BOOL open); SOCKET open_socket(int type, const char* protocol); SOCKET accept_socket(SOCKET s, union xp_sockaddr* addr, socklen_t* addrlen); diff --git a/src/sbbs3/un_qwk.cpp b/src/sbbs3/un_qwk.cpp index bf4d94c0d6..36dee8ee49 100644 --- a/src/sbbs3/un_qwk.cpp +++ b/src/sbbs3/un_qwk.cpp @@ -166,7 +166,7 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum) && (now-msg.hdr.when_written.time)/(24*60*60) > cfg.max_qwkmsgage) { eprintf(LOG_NOTICE,"!Filtering QWK message from %s due to age: %u days" ,msg.from - ,(now-msg.hdr.when_written.time)/(24*60*60)); + ,(unsigned int)(now-msg.hdr.when_written.time)/(24*60*60)); continue; } -- GitLab