Skip to content
Snippets Groups Projects
Commit c1d232e0 authored by rswindell's avatar rswindell
Browse files

Use GCC-assisted printf-style format/arg checking to find and fix instances

of lprintf() misuse.
parent 53754d3c
No related branches found
No related tags found
No related merge requests found
...@@ -106,7 +106,11 @@ bool terminated=false; ...@@ -106,7 +106,11 @@ bool terminated=false;
str_list_t locked_bso_nodes; str_list_t locked_bso_nodes;
int lprintf(int level, char *fmt, ...); int lprintf(int level, char *fmt, ...)
#if defined(__GNUC__) // Catch printf-format errors
__attribute__ ((format (printf, 2, 3)));
#endif
;
int mv(const char *insrc, const char *indest, bool copy); int mv(const char *insrc, const char *indest, bool copy);
time32_t fmsgtime(const char *str); time32_t fmsgtime(const char *str);
void export_echomail(const char *sub_code, const nodecfg_t*, bool rescan); void export_echomail(const char *sub_code, const nodecfg_t*, bool rescan);
...@@ -418,7 +422,7 @@ size_t read_echostats(const char* fname, echostat_t **echostat) ...@@ -418,7 +422,7 @@ size_t read_echostats(const char* fname, echostat_t **echostat)
iniFreeStringList(echoes); iniFreeStringList(echoes);
iniFreeStringList(ini); iniFreeStringList(ini);
lprintf(LOG_DEBUG, "Read %u echo statistics from %s", echo_count, fname); lprintf(LOG_DEBUG, "Read %lu echo statistics from %s", echo_count, fname);
return echo_count; return echo_count;
} }
...@@ -1487,7 +1491,7 @@ void netmail_arealist(enum arealist_type type, fidoaddr_t addr, const char* to) ...@@ -1487,7 +1491,7 @@ void netmail_arealist(enum arealist_type type, fidoaddr_t addr, const char* to)
fclose(fp); fclose(fp);
} }
} }
lprintf(LOG_INFO,"AreaFix (for %s) Created response netmail with %s (%u areas)" lprintf(LOG_INFO,"AreaFix (for %s) Created response netmail with %s (%lu areas)"
, smb_faddrtoa(&addr, NULL), title, strListCount(area_list)); , smb_faddrtoa(&addr, NULL), title, strListCount(area_list));
strListFree(&area_list); strListFree(&area_list);
} }
...@@ -1811,10 +1815,10 @@ void alter_areas(str_list_t add_area, str_list_t del_area, fidoaddr_t addr, cons ...@@ -1811,10 +1815,10 @@ void alter_areas(str_list_t add_area, str_list_t del_area, fidoaddr_t addr, cons
fclose(nmfile); fclose(nmfile);
fclose(afileout); fclose(afileout);
if(added) if(added)
lprintf(LOG_DEBUG, "AreaFix (for %s) Added links to %u areas in %s" lprintf(LOG_DEBUG, "AreaFix (for %s) Added links to %lu areas in %s"
,smb_faddrtoa(&addr,NULL), added, cfg.areafile); ,smb_faddrtoa(&addr,NULL), added, cfg.areafile);
if(deleted) if(deleted)
lprintf(LOG_DEBUG, "AreaFix (for %s) Removed links to %u areas in %s" lprintf(LOG_DEBUG, "AreaFix (for %s) Removed links to %lu areas in %s"
,smb_faddrtoa(&addr,NULL), deleted, cfg.areafile); ,smb_faddrtoa(&addr,NULL), deleted, cfg.areafile);
if(added || deleted) { if(added || deleted) {
if(cfg.areafile_backups == 0 || !backup(cfg.areafile, cfg.areafile_backups, /* ren: */TRUE)) if(cfg.areafile_backups == 0 || !backup(cfg.areafile, cfg.areafile_backups, /* ren: */TRUE))
...@@ -2920,7 +2924,7 @@ void cleanup(void) ...@@ -2920,7 +2924,7 @@ void cleanup(void)
char path[MAX_PATH+1]; char path[MAX_PATH+1];
if(bad_areas != NULL) { if(bad_areas != NULL) {
lprintf(LOG_DEBUG, "Writing %u areas to %s", strListCount(bad_areas), cfg.badareafile); lprintf(LOG_DEBUG, "Writing %lu areas to %s", strListCount(bad_areas), cfg.badareafile);
FILE* fp = fopen(cfg.badareafile, "wt"); FILE* fp = fopen(cfg.badareafile, "wt");
if(fp == NULL) { if(fp == NULL) {
lprintf(LOG_ERR, "ERROR %d (%s) opening %s", errno, strerror(errno), cfg.badareafile); lprintf(LOG_ERR, "ERROR %d (%s) opening %s", errno, strerror(errno), cfg.badareafile);
...@@ -5116,7 +5120,7 @@ int export_netmail(void) ...@@ -5116,7 +5120,7 @@ int export_netmail(void)
int result = fwrite(filedata, filelen, 1, fp); int result = fwrite(filedata, filelen, 1, fp);
fclose(fp); fclose(fp);
if(!result) if(!result)
lprintf(LOG_ERR, "!ERROR %d (%s) writing %lu bytes to %s", errno, strerror(errno), filelen, fpath); lprintf(LOG_ERR, "!ERROR %d (%s) writing %u bytes to %s", errno, strerror(errno), filelen, fpath);
else { else {
lprintf(LOG_DEBUG, "Decoded MIME attachment stored as: %s", fpath); lprintf(LOG_DEBUG, "Decoded MIME attachment stored as: %s", fpath);
file_attached = true; file_attached = true;
...@@ -5128,7 +5132,7 @@ int export_netmail(void) ...@@ -5128,7 +5132,7 @@ int export_netmail(void)
} }
if((txt=smb_getmsgtxt(email,&msg,GETMSGTXT_ALL|GETMSGTXT_PLAIN)) == NULL) { if((txt=smb_getmsgtxt(email,&msg,GETMSGTXT_ALL|GETMSGTXT_PLAIN)) == NULL) {
lprintf(LOG_ERR,"!ERROR %d getting message text for mail msg #%u" lprintf(LOG_ERR,"!ERROR %s getting message text for mail msg #%u"
, email->last_error, msg.hdr.number); , email->last_error, msg.hdr.number);
continue; continue;
} }
...@@ -5149,7 +5153,7 @@ int export_netmail(void) ...@@ -5149,7 +5153,7 @@ int export_netmail(void)
/* Just mark as "sent" */ /* Just mark as "sent" */
msg.hdr.netattr |= MSG_SENT; msg.hdr.netattr |= MSG_SENT;
if(smb_putmsghdr(email, &msg) != SMB_SUCCESS) if(smb_putmsghdr(email, &msg) != SMB_SUCCESS)
lprintf(LOG_ERR,"!ERROR %d updating msg header for mail msg #%u" lprintf(LOG_ERR,"!ERROR %s updating msg header for mail msg #%u"
, email->last_error, msg.hdr.number); , email->last_error, msg.hdr.number);
if(msg.hdr.auxattr&MSG_KILLFILE) if(msg.hdr.auxattr&MSG_KILLFILE)
delfattach(&scfg, &msg); delfattach(&scfg, &msg);
...@@ -5442,7 +5446,7 @@ void find_stray_packets(void) ...@@ -5442,7 +5446,7 @@ void find_stray_packets(void)
continue; continue;
} }
if(fread(&pkthdr,sizeof(pkthdr),1,fp)!=1) { if(fread(&pkthdr,sizeof(pkthdr),1,fp)!=1) {
lprintf(LOG_ERR,"ERROR reading header (%u bytes) from stray packet: %s" lprintf(LOG_ERR,"ERROR reading header (%lu bytes) from stray packet: %s"
,sizeof(pkthdr), packet); ,sizeof(pkthdr), packet);
fclose(fp); fclose(fp);
delfile(packet, __LINE__); delfile(packet, __LINE__);
...@@ -5485,7 +5489,7 @@ void find_stray_packets(void) ...@@ -5485,7 +5489,7 @@ void find_stray_packets(void)
listAddNode(&outpkt_list, pkt, 0, LAST_NODE); listAddNode(&outpkt_list, pkt, 0, LAST_NODE);
} }
if(g.gl_pathc) if(g.gl_pathc)
lprintf(LOG_DEBUG, "%u stray outbound packets (%u total pkts) found in %s" lprintf(LOG_DEBUG, "%lu stray outbound packets (%lu total pkts) found in %s"
,listCountNodes(&outpkt_list), g.gl_pathc, cfg.temp_dir); ,listCountNodes(&outpkt_list), g.gl_pathc, cfg.temp_dir);
globfree(&g); globfree(&g);
} }
...@@ -5569,7 +5573,7 @@ void import_packets(const char* inbound, nodecfg_t* inbox, bool secure) ...@@ -5569,7 +5573,7 @@ void import_packets(const char* inbound, nodecfg_t* inbox, bool secure)
(void)fseek(fidomsg,0L,SEEK_SET); (void)fseek(fidomsg,0L,SEEK_SET);
if(fread(&pkthdr,sizeof(pkthdr),1,fidomsg)!=1) { if(fread(&pkthdr,sizeof(pkthdr),1,fidomsg)!=1) {
fclose(fidomsg); fclose(fidomsg);
lprintf(LOG_ERR,"ERROR line %d reading %u bytes from %s",__LINE__ lprintf(LOG_ERR,"ERROR line %d reading %lu bytes from %s",__LINE__
,sizeof(pkthdr),packet); ,sizeof(pkthdr),packet);
rename_bad_packet(packet); rename_bad_packet(packet);
continue; continue;
...@@ -5638,7 +5642,7 @@ void import_packets(const char* inbound, nodecfg_t* inbox, bool secure) ...@@ -5638,7 +5642,7 @@ void import_packets(const char* inbound, nodecfg_t* inbox, bool secure)
hdr.cost = pkdmsg.cost; hdr.cost = pkdmsg.cost;
SAFECOPY(hdr.time,pkdmsg.time); SAFECOPY(hdr.time,pkdmsg.time);
} else { } else {
lprintf(LOG_NOTICE, "Grunged message (type %d) from %s at offset %u in packet: %s" lprintf(LOG_NOTICE, "Grunged message (type %d) from %s at offset %ld in packet: %s"
, pkdmsg.type, smb_faddrtoa(&pkt_orig, NULL), msg_offset, packet); , pkdmsg.type, smb_faddrtoa(&pkt_orig, NULL), msg_offset, packet);
printf("Grunged message!\n"); printf("Grunged message!\n");
bad_packet = true; bad_packet = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment