enable gcc to check arguments of printf-like functions

Check printf-like functions like conoutf, if format strings and argument
lists match.

This commit also fixes a lot of code parts that actually had mismatching
argument lists - or did things, that this check does not like.

numtime() was rewritten in an ugly but very portable fashion (it's
recommended to stay away from "long long" format entries, because errors
usually only come up at runtime).

(some code was copied from sauer)
This commit is contained in:
ac-stef
2015-08-02 19:40:41 +02:00
parent b2845b7c15
commit 826499c12d
20 changed files with 77 additions and 71 deletions
+14 -12
View File
@@ -53,7 +53,7 @@ struct sline
sline() : bgcolor(NULL), textcolor(0) { copystring(s, ""); }
void addcol(int priority, const char *format = NULL, ...)
void addcol(int priority, const char *format = NULL, ...) PRINTFARGS(3, 4)
{
if(priority < 0) return;
coldata &col = cols.add();
@@ -193,9 +193,9 @@ void renderdiscscores(int team)
line.addcol(sc_deaths, "%d", d.deaths);
line.addcol(sc_ratio, "%.2f", SCORERATIO(d.frags, d.deaths));
if(multiplayer(false) || watchingdemo) line.addcol(sc_score, "%d", max(d.points, 0));
line.addcol(sc_lag, clag);
line.addcol(sc_lag, "%s", clag);
line.addcol(sc_clientnum, "DISC");
line.addcol(sc_name, d.name);
line.addcol(sc_name, "%s", d.name);
}
}
@@ -227,7 +227,7 @@ void renderscore(playerent *d)
if(multiplayer(false) || watchingdemo)
{
line.addcol(sc_score, "%d", max(d->points, 0));
line.addcol(sc_lag, lagping);
line.addcol(sc_lag, "%s", lagping);
}
line.addcol(sc_clientnum, "\fs\f%d%d\fr", cncolumncolor, d->clientnum);
char flagicon = '\0';
@@ -243,7 +243,7 @@ void renderscore(playerent *d)
int totalplayers = 0;
int renderteamscore(teamscore *t)
void renderteamscore(teamscore *t)
{
if(!scorelines.empty()) // space between teams
{
@@ -251,8 +251,6 @@ int renderteamscore(teamscore *t)
space.s[0] = 0;
}
sline &line = scorelines.add();
int n = t->teammembers.length();
defformatstring(plrs)("(%d %s)", n, n == 1 ? "player" : "players");
if(m_flags) line.addcol(sc_flags, "%d", t->flagscore);
line.addcol(sc_frags, "%d", t->frags);
@@ -263,13 +261,13 @@ int renderteamscore(teamscore *t)
line.addcol(sc_score, "%d", max(t->points, 0));
line.addcol(sc_lag);
}
line.addcol(sc_clientnum, team_string(t->team));
line.addcol(sc_name, plrs);
line.addcol(sc_clientnum, "%s", team_string(t->team));
int n = t->teammembers.length();
line.addcol(sc_name, "(%d %s)", n, n == 1 ? "player" : "players");
static color teamcolors[2] = { color(1.0f, 0, 0, 0.2f), color(0, 0, 1.0f, 0.2f) };
line.bgcolor = &teamcolors[team_base(t->team)];
loopv(t->teammembers) renderscore(t->teammembers[i]);
return n;
}
extern bool watchingdemo;
@@ -405,7 +403,11 @@ void renderscores(void *menu, bool init)
serverinfo *s = getconnectedserverinfo();
if(s)
{
if(servstate.mastermode > MM_OPEN) concatformatstring(serverline, servstate.mastermode == MM_MATCH ? "M%d " : "P ", servstate.matchteamsize);
if(servstate.mastermode > MM_OPEN)
{
if(servstate.mastermode == MM_MATCH) concatformatstring(serverline, "M%d ", servstate.matchteamsize);
else concatstring(serverline, "P ");
}
// ft: 2010jun12: this can write over the menu boundary
//concatformatstring(serverline, "%s:%d %s", s->name, s->port, s->sdesc);
// for now we'll just cut it off, same as the serverbrowser
@@ -458,7 +460,7 @@ const char *asciiscores(bool destjpg)
}
if(getclientmap()[0])
{
formatstring(text)("\n\"%s\" on map %s", modestr(gamemode, 0), getclientmap(), asctime());
formatstring(text)("\n\"%s\" on map %s", modestr(gamemode, 0), getclientmap());
addstr(buf, text);
}
if(multiplayer(false))