From 826499c12dd49a5fc9110f035d6270fa863ad40e Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 2 Aug 2015 19:40:41 +0200 Subject: [PATCH] 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) --- source/src/Makefile | 4 ++-- source/src/bot/bot_waypoint.cpp | 4 +--- source/src/client.cpp | 2 +- source/src/clientgame.cpp | 6 +++--- source/src/main.cpp | 2 +- source/src/physics.cpp | 2 +- source/src/protos.h | 20 ++++++++++---------- source/src/renderhud.cpp | 6 ++++-- source/src/scoreboard.cpp | 26 ++++++++++++++------------ source/src/server.cpp | 3 ++- source/src/serverbrowser.cpp | 6 ++++-- source/src/serverfiles.h | 4 ++-- source/src/sound.h | 2 +- source/src/stream.cpp | 2 +- source/src/tools.cpp | 6 ++++-- source/src/tools.h | 20 +++++++++++--------- source/src/vertmodel.h | 2 +- source/src/weapon.cpp | 9 ++------- source/src/worldio.cpp | 16 +++++++++------- source/src/zip.cpp | 6 +++--- 20 files changed, 77 insertions(+), 71 deletions(-) diff --git a/source/src/Makefile b/source/src/Makefile index c4f94311..081b9c30 100644 --- a/source/src/Makefile +++ b/source/src/Makefile @@ -1,6 +1,6 @@ # Ideally, you can override these parameters directly via the commandline, or by # creating a seperate 'Makefile_local' file (this way, your changes aren't -# accidentaly commited to the AssaultCube repository). +# accidentally commited to the AssaultCube repository). # AssaultCube now uses clang++ as a compiler, as there have been random crashes # found to have been caused by the g++ compiler in the past. This seems to have @@ -30,7 +30,7 @@ ifneq (,$(findstring clang,$(CXX))) override CXXFLAGS+= -Wall -fsigned-char else CXXFLAGS= -O3 -fomit-frame-pointer - override CXXFLAGS+= -Wall -fsigned-char -ffast-math -rdynamic + override CXXFLAGS+= -Wall -fsigned-char -ffast-math -rdynamic -Wno-format-zero-length endif INCLUDES= -I. -Ibot -I../enet/include diff --git a/source/src/bot/bot_waypoint.cpp b/source/src/bot/bot_waypoint.cpp index 3370574e..26275545 100644 --- a/source/src/bot/bot_waypoint.cpp +++ b/source/src/bot/bot_waypoint.cpp @@ -1403,9 +1403,7 @@ void CWaypointClass::FloodThink() BotManager.CalculateMaxAStarCount(); - char szSize[64]; - sprintf(szSize, "Total size: %.2f Kb", float(m_iFloodSize)/1024.0f); - conoutf(szSize); + conoutf("Total size: %.2f Kb", float(m_iFloodSize)/1024.0f); } bool CWaypointClass::CanPlaceNodeHere(const vec &from) diff --git a/source/src/client.cpp b/source/src/client.cpp index 2d6cf6e0..871832e5 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -1025,7 +1025,7 @@ int processdownload(package *pck) { const char *pckname = findfile(path(pck->name, true), "w+"); // with textures/sounds, the image/audio file itself is sent. Just need to copy it from the temporary file - if(rename(tmpname, pckname)) conoutf("\f3failed to install", pckname); + if(rename(tmpname, pckname)) conoutf("\f3failed to install %s", pckname); if(pck->type == PCK_TEXTURE) rereadtexturelists = 1; else rereadsoundlists = 1; break; diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index dd582d4d..d93fe8d2 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -249,7 +249,7 @@ void playerinfo(int *cn, const char *attr) if(!p) { if(!m_botmode && multiplayer(false)) // bot clientnums are still glitchy, causing this message to sometimes appear in offline/singleplayer when it shouldn't??? -Bukz 2012may - conoutf("invalid clientnum cn: %s attr: %s", cn, attr); + conoutf("invalid clientnum cn: %d attr: %s", clientnum, attr); return; } @@ -544,8 +544,8 @@ bool showhudtimer(int maxsecs, int startmillis, const char *msg, bool flash) concatstring(str, sec); } } - if(nextticks < maxticks) hudeditf(HUDMSG_TIMER|HUDMSG_OVERWRITE, flash ? str : str+2); - else hudeditf(HUDMSG_TIMER, msg); + if(nextticks < maxticks) hudeditf(HUDMSG_TIMER|HUDMSG_OVERWRITE, "%s", flash ? str : str+2); + else hudeditf(HUDMSG_TIMER, "%s", msg); return true; } diff --git a/source/src/main.cpp b/source/src/main.cpp index 708e9bdd..b1dea776 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -984,7 +984,7 @@ void connectprotocol(char *protocolstring, string &servername, int &serverport, servername[0] = password[0] = '\0'; serverport = 0; while(*c && *c!='/' && *c!='?' && *c!=':') { len++; c++; } - if(!len) { conoutf("\f3bad commandline syntax", protocolstring); return; } + if(!len) { conoutf("\f3bad commandline syntax (\"%s\")", protocolstring); return; } copystring(servername, p, min(len+1, MAXSTRLEN)); direct_connect = true; if(*c && *c==':') diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 3394cd53..32c6f1c7 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -1066,7 +1066,7 @@ void entinmap(physent *d) // brute force but effective way to find a free spa } // leave ent at original pos, possibly stuck d->resetinterp(); - conoutf("can't find entity spawn spot! (%d, %d)", d->o.x, d->o.y); + conoutf("can't find entity spawn spot! (%d, %d)", int(d->o.x), int(d->o.y)); } void vecfromyawpitch(float yaw, float pitch, int move, int strafe, vec &m) diff --git a/source/src/protos.h b/source/src/protos.h index cce4a0ef..32505d29 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -64,7 +64,7 @@ extern void savehistory(); extern void loadhistory(); extern void writebinds(stream *f); extern void pasteconsole(char *dst); -extern void clientlogf(const char *s, ...); +extern void clientlogf(const char *s, ...) PRINTFARGS(1, 2); struct keym { @@ -577,7 +577,7 @@ extern font *getfont(const char *name); extern void pushfont(const char *name); extern void popfont(); extern void draw_text(const char *str, int left, int top, int r = 255, int g = 255, int b = 255, int a = 255, int cursor = -1, int maxwidth = -1); -extern void draw_textf(const char *fstr, int left, int top, ...); +extern void draw_textf(const char *fstr, int left, int top, ...) PRINTFARGS(1, 4); extern int text_width(const char *str); extern int text_visible(const char *str, int max); extern void text_bounds(const char *str, int &width, int &height, int maxwidth = -1); @@ -625,10 +625,10 @@ enum HUDMSG_OVERWRITE = 1<<8 }; extern void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater); -extern void loadingscreen(const char *fmt = NULL, ...); -extern void hudoutf(const char *s, ...); -extern void hudonlyf(const char *s, ...); -extern void hudeditf(int type, const char *s, ...); +extern void loadingscreen(const char *fmt = NULL, ...) PRINTFARGS(1, 2); +extern void hudoutf(const char *s, ...) PRINTFARGS(1, 2); +extern void hudonlyf(const char *s, ...) PRINTFARGS(1, 2); +extern void hudeditf(int type, const char *s, ...) PRINTFARGS(2, 3); extern void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2 = 0, const char *text2 = NULL); extern void updatedmgindicator(vec &attack); extern vec getradarpos(); @@ -827,7 +827,7 @@ extern void freechallenge(void *answer); extern bool checkchallenge(const char *answerstr, void *correct); // console -extern void conoutf(const char *s, ...); +extern void conoutf(const char *s, ...) PRINTFARGS(1, 2); // command extern bool per_idents, neverpersist; @@ -843,7 +843,7 @@ extern bool identexists(const char *name); extern bool addcommand(const char *name, void (*fun)(), const char *sig); extern int execute(const char *p); enum { HOOK_SP_MP = 1, HOOK_SP, HOOK_MP, HOOK_FLAGMASK = 0xff, HOOK_TEAM = 0x100, HOOK_NOTEAM = 0x200, HOOK_BOTMODE = 0x400, HOOK_FLAGMODE = 0x800, HOOK_ARENA = 0x1000 }; -extern bool exechook(int context, const char *ident, const char *body,...); // execute cubescript hook if available and allowed in current context/gamemode +extern bool exechook(int context, const char *ident, const char *body,...) PRINTFARGS(3, 4); // execute cubescript hook if available and allowed in current context/gamemode extern char *executeret(const char *p); extern char *conc(const char **w, int n, bool space); extern void intret(int v); @@ -885,7 +885,7 @@ extern void localservertoclient(int chan, uchar *buf, int len, bool demo = false extern const char *modestr(int n, bool acronyms = false); extern const char *voteerrorstr(int n); extern const char *mmfullname(int n); -extern void fatal(const char *s, ...); +extern void fatal(const char *s, ...) PRINTFARGS(1, 2); extern void initserver(bool dedicated, int argc = 0, char **argv = NULL); extern void cleanupserver(); extern void localconnect(); @@ -954,7 +954,7 @@ enum { ACLOG_DEBUG = 0, ACLOG_VERBOSE, ACLOG_INFO, ACLOG_WARNING, ACLOG_ERROR, A extern bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp); extern void exitlogging(); -extern bool logline(int level, const char *msg, ...); +extern bool logline(int level, const char *msg, ...) PRINTFARGS(2, 3); // server config diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 3d4694ac..c7cce21d 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -311,7 +311,9 @@ void drawequipicons(playerent *p) glEnable(GL_BLEND); } -void drawradarent(float x, float y, float yaw, int col, int row, float iconsize, bool pulse, const char *label = NULL, ...) +void drawradarent(float x, float y, float yaw, int col, int row, float iconsize, bool pulse, const char *label = NULL, ...) PRINTFARGS(8, 9); + +void drawradarent(float x, float y, float yaw, int col, int row, float iconsize, bool pulse, const char *label, ...) { glPushMatrix(); if(pulse) glColor4f(1.0f, 1.0f, 1.0f, 0.2f+(sinf(lastmillis/30.0f)+1.0f)/2.0f); @@ -1051,7 +1053,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat defformatstring(count)("%d", flagscores[i]); int cw, ch; text_bounds(count, cw, ch); - draw_textf(count, i*120+VIRTW/4.0f*3.0f+60-cw/2, 1590); + draw_textf("%s", i * 120 + VIRTW / 4.0f * 3.0f + 60 - cw / 2, 1590, count); } } diff --git a/source/src/scoreboard.cpp b/source/src/scoreboard.cpp index 7eef3fe3..37e96e0c 100644 --- a/source/src/scoreboard.cpp +++ b/source/src/scoreboard.cpp @@ -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)) diff --git a/source/src/server.cpp b/source/src/server.cpp index 2e0e1084..fb19fb05 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -3762,7 +3762,8 @@ void loggamestatus(const char *reason) savedscore &sc = savedscores[i]; if(sc.valid) { - formatstring(text)(m_teammode ? "%-4s " : "", team_string(sc.team, true)); + if(m_teammode) formatstring(text)("%-4s ", team_string(sc.team, true)); + else text[0] = '\0'; if(m_flags) concatformatstring(text, "%4d ", sc.flagscore); logline(ACLOG_INFO, " %-16s %s%4d %5d%s - disconnected", sc.name, text, sc.frags, sc.deaths, m_teammode ? " -" : ""); if(sc.team != TEAM_SPECT) diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index e7ff7448..46c3bece 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -1076,7 +1076,8 @@ void refreshservers(void *menu, bool init) if(!hidefavicons && !showweights && showfavtag && si.favcat > -1) favimage = getalias(favcatargname(favcats[si.favcat], FC_IMAGE)); copystring(text, si.favcat > -1 && !favimage ? favcattags[si.favcat] : ""); if(showweights) concatformatstring(text, "(%d)", si.weight); - formatstring(si.full)(showfavtag ? (favimage ? "\t" : "\fs%s\fr\t") : "", text); + if(showfavtag && !favimage) formatstring(si.full)("\fs%s\fr\t", text); + else copystring(si.full, showfavtag ? "\t" : ""); concatformatstring(si.full, "\fs\f%c%s\t\fs\f%c%d/%d\fr\t\a%c ", basecolor, colorping(si.ping), plnumcolor, si.numplayers, si.maxclients, '0' + si.uplinkqual); if(si.map[0]) { @@ -1084,7 +1085,8 @@ void refreshservers(void *menu, bool init) if(showmr) concatformatstring(si.full, ", (%d)", si.minremain); } else concatformatstring(si.full, "empty"); - concatformatstring(si.full, serverbrowserhideip < 2 ? ": \fs%s%s:%d\fr" : ": ", serverbrowserhideip == 1 ? "\f4" : "", si.name, si.port); + concatstring(si.full, ": "); + if(serverbrowserhideip < 2) concatformatstring(si.full, "\fs%s%s:%d\fr", serverbrowserhideip == 1 ? "\f4" : "", si.name, si.port); concatformatstring(si.full, "\fr %s", si.sdesc); } } diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index 118739ab..87f66b91 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -238,7 +238,7 @@ float Mheight = 0; bool mapisok(mapstats *ms) { if ( Mheight > MAXMHEIGHT ) { logline(ACLOG_INFO, "MAP CHECK FAIL: The overall ceil height is too high (%.1f cubes)", Mheight); return false; } - if ( Mopen > MAXMAREA ) { logline(ACLOG_INFO, "MAP CHECK FAIL: There is a big open area in this (hint: use more solid walls)", Mheight); return false; } + if ( Mopen > MAXMAREA ) { logline(ACLOG_INFO, "MAP CHECK FAIL: There is a big open area in this (hint: use more solid walls)"); return false; } if ( SHhits > MAXHHITS ) { logline(ACLOG_INFO, "MAP CHECK FAIL: Too high height in some parts of the map (%d hits)", SHhits); return false; } if ( ms->hasflags ) // Check if flags are ok @@ -927,7 +927,7 @@ struct killmessagesfile : serverconfigfile } if(strlen(message)>MAXKILLMSGLEN) { - logline(ACLOG_INFO, " error in line %i, too long message : string length is %i, max. allowed is %i", line, strlen(message), MAXKILLMSGLEN); + logline(ACLOG_INFO, " error in line %i, too long message : string length is %i, max. allowed is %i", line, int(strlen(message)), MAXKILLMSGLEN); errors++; } if(!errors) diff --git a/source/src/sound.h b/source/src/sound.h index 648c8b14..b0dc8fff 100644 --- a/source/src/sound.h +++ b/source/src/sound.h @@ -438,7 +438,7 @@ public: }; void alclearerr(); -bool alerr(bool msg = true, int line = 0, const char *s = NULL, ...); +bool alerr(bool msg = true, int line = 0, const char *s = NULL, ...) PRINTFARGS(3, 4); #define ALERR alerr(true, __LINE__) #define ALERRF(fmt, ...) alerr(true, __LINE__, fmt, __VA_ARGS__) diff --git a/source/src/stream.cpp b/source/src/stream.cpp index 8eb215df..4a67ea82 100644 --- a/source/src/stream.cpp +++ b/source/src/stream.cpp @@ -611,7 +611,7 @@ struct gzstream : stream if(checkcrc != crc) conoutf("gzip crc check failed: read %X, calculated %X", checkcrc, crc); if(checksize != zfile.total_out) - conoutf("gzip size check failed: read %d, calculated %d", checksize, zfile.total_out); + conoutf("gzip size check failed: read %u, calculated %u", checksize, (uint) zfile.total_out); } #endif } diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 06b286a1..4e31d5f0 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -20,8 +20,10 @@ const char *asctime() const char *numtime() { static string numt; - formatstring(numt)("%ld", (long long) time(NULL)); - return numt; + time_t t = time(NULL); + int t1 = t / 1000000, t2 = t % 1000000; + formatstring(numt)("%d%06d", t1, t2); + return numt + strspn(numt, "0"); } static const uchar transformenttab[] = { diff --git a/source/src/tools.h b/source/src/tools.h index 091d344b..ec6c4f73 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -105,6 +105,13 @@ static inline float round(float x) { return floor(x + 0.5f); } #define PATHDIVS "/" #endif +#ifdef __GNUC__ +#define PRINTFARGS(fmt, args) __attribute__((format(printf, fmt, args))) +//#pragma GCC diagnostic ignored "-Wformat-zero-length" // apparently doesn't work from precompiled header -> moved to makefile +#else +#define PRINTFARGS(fmt, args) +#endif + // easy safe strings #define MAXSTRLEN 260 @@ -113,13 +120,13 @@ typedef char string[MAXSTRLEN]; inline void vformatstring(char *d, const char *fmt, va_list v, int len = MAXSTRLEN) { _vsnprintf(d, len, fmt, v); d[len-1] = 0; } inline char *copystring(char *d, const char *s, size_t len = MAXSTRLEN) { strncpy(d, s, len); d[len-1] = 0; return d; } inline char *concatstring(char *d, const char *s, size_t len = MAXSTRLEN) { size_t used = strlen(d); return used < len ? copystring(d+used, s, len-used) : d; } -extern char *concatformatstring(char *d, const char *s, ...); +extern char *concatformatstring(char *d, const char *s, ...) PRINTFARGS(2, 3); struct stringformatter { char *buf; stringformatter(char *buf): buf((char *)buf) {} - void operator()(const char *fmt, ...) + void operator()(const char *fmt, ...) PRINTFARGS(2, 3) { va_list v; va_start(v, fmt); @@ -132,11 +139,6 @@ struct stringformatter #define defformatstring(d) string d; formatstring(d) #define defvformatstring(d,last,fmt) string d; { va_list ap; va_start(ap, last); vformatstring(d, fmt, ap); va_end(ap); } -//#define s_sprintf(d) s_sprintf_f((char *)d) -//#define s_sprintfd(d) string d; s_sprintf(d) -//#define s_sprintfdlv(d,last,fmt) string d; { va_list ap; va_start(ap, last); formatstring(d, fmt, ap); va_end(ap); } -//#define s_sprintfdv(d,fmt) s_sprintfdlv(d,fmt,fmt) - inline char *strcaps(const char *s, bool on) { static string r; @@ -912,7 +914,7 @@ struct stream virtual bool getline(char *str, int len); virtual bool putstring(const char *str) { int len = (int)strlen(str); return write(str, len) == len; } virtual bool putline(const char *str) { return putstring(str) && putchar('\n'); } - virtual int printf(const char *fmt, ...) { return -1; } + virtual int printf(const char *fmt, ...) PRINTFARGS(2, 3) { return -1; } virtual uint getcrc() { return 0; } template bool put(T n) { return write(&n, sizeof(n)) == sizeof(n); } @@ -980,7 +982,7 @@ extern const char *iptoa(const enet_uint32 ip); extern const char *iprtoa(const struct iprange &ipr); extern int cmpiprange(const struct iprange *a, const struct iprange *b); extern int cmpipmatch(const struct iprange *a, const struct iprange *b); -extern int cvecprintf(vector &v, const char *s, ...); +extern int cvecprintf(vector &v, const char *s, ...) PRINTFARGS(2, 3); extern const char *hiddenpwd(const char *pwd, int showchars = 0); extern int getlistindex(const char *key, const char *list[], bool acceptnumeric = true, int deflt = -1); diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index 972a94dc..38d31a2a 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -350,7 +350,7 @@ __attribute__((optimize(2))) } } - if(dbgstenc >= (owner->numframes > 1 || as.anim&ANIM_DYNALLOC ? 2 : 1)) conoutf("%s: %d tris", owner->filename, (idx - d->idxs())/3); + if(dbgstenc >= (owner->numframes > 1 || as.anim&ANIM_DYNALLOC ? 2 : 1)) conoutf("%s: %d tris", owner->filename, int((idx - d->idxs()) / 3)); d->size = (uchar *)idx - (uchar *)d; return d; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 815a0794..c724261f 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -742,13 +742,8 @@ void r_accuracy(int h) if(rows<1) return; cols++; blendbox(x_offset, spacing+y_offset, spacing+x_offset+curfont->defaultw*cols, y_offset-curfont->defaulth*rows, true, -1); - int x=0; - loopv(lines) - { - char *line = lines[i]; - draw_textf(line,spacing*0.5+x_offset,y_offset-x*curfont->defaulth-0.5*spacing); - x++; - } + int x = spacing * 0.5 + x_offset, y = y_offset - 0.5 * spacing; + loopv(lines) draw_textf("%s", x, y - i * curfont->defaulth, lines[i]); } void accuracyreset() diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 1b0a0b14..d9365f80 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -21,10 +21,11 @@ const char *setnames(const char *name) copystring(pakname, "maps"); copystring(mapname, name); } + const char *nt = numtime(); formatstring(cgzname)("packages/%s/%s.cgz", pakname, mapname); formatstring(ocgzname)("packages/maps/official/%s.cgz", mapname); - formatstring(bakname)("packages/%s/%s_%s.BAK", pakname, mapname, numtime()); - formatstring(cbakname)("packages/%s/%s.cfg_%s.BAK", pakname, mapname, numtime()); + formatstring(bakname)("packages/%s/%s_%s.BAK", pakname, mapname, nt); + formatstring(cbakname)("packages/%s/%s.cfg_%s.BAK", pakname, mapname, nt); formatstring(pcfname)("packages/%s/package.cfg", pakname); formatstring(mcfname)("packages/%s/%s.cfg", pakname, mapname); formatstring(omcfname)("packages/maps/official/%s.cfg", mapname); @@ -194,7 +195,7 @@ void rldecodecubes(ucharbuf &f, sqr *s, int len, int version, bool silent) // ru { case -1: { - if(!silent) conoutf("while reading map at %d: unexpected end of file", cubicsize - (e - s)); + if(!silent) conoutf("while reading map at %ld: unexpected end of file", cubicsize - (e - s)); f.forceoverread(); silent = true; sqrdefault(s); @@ -230,7 +231,7 @@ void rldecodecubes(ucharbuf &f, sqr *s, int len, int version, bool silent) // ru { if(type<0 || type>=MAXTYPE) { - if(!silent) conoutf("while reading map at %d: type %d out of range", cubicsize - (e - s), type); + if(!silent) conoutf("while reading map at %ld: type %d out of range", cubicsize - (e - s), type); f.overread(); continue; } @@ -873,7 +874,8 @@ void hexbinwrite(stream *f, void *data, int len, bool ascii = true) // write b asc[i] = isalnum(*s) ? *s : '.'; asc[i + 1] = '\0'; f->printf(" %02x", int(*s++)); } - f->printf(ascii ? " // %s\n" : "\n", asc); + if(ascii) f->printf(" // %s\n", asc); + else f->printf("\n"); len -= chunk; } } @@ -984,7 +986,7 @@ struct xmap void write(stream *f) // write xmap as cubescript to a file { - f->printf("restorexmap version %d %d %d\n", XMAPVERSION, isbigendian() ? 1 : 0, sizeof(world)); // it is a non-portable binary file format, so we have to check... + f->printf("restorexmap version %d %d %d\n", XMAPVERSION, isbigendian() ? 1 : 0, int(sizeof(world))); // it is a non-portable binary file format, so we have to check... f->printf("restorexmap names \"%s\" \"%s\"\n", name, mcfname); f->printf("restorexmap sizes %d %d %d\n", ssize, cubicsize, numundo); hexbinwrite(f, &hdr, sizeof(header)); @@ -1153,7 +1155,7 @@ void restorexmap(char **args, int numargs) // read an xmap from a cubescript f switch(cmd) { case 0: // version - if(ATOI(args[1]) != XMAPVERSION || ATOI(args[2]) != (isbigendian() ? 1 : 0) || ATOI(args[3]) != sizeof(world)) + if(ATOI(args[1]) != XMAPVERSION || ATOI(args[2]) != (isbigendian() ? 1 : 0) || ATOI(args[3]) != int(sizeof(world))) { conoutf("restorexmap: file is from different game version"); abort = true; diff --git a/source/src/zip.cpp b/source/src/zip.cpp index b4244951..f4504ee4 100644 --- a/source/src/zip.cpp +++ b/source/src/zip.cpp @@ -157,7 +157,7 @@ static bool readzipdirectory(const char *archname, FILE *f, int entries, int off f.size = hdr.uncompressedsize; f.compressedsize = hdr.compression ? hdr.compressedsize : 0; #ifndef STANDALONE - if(dbgzip) conoutf("file %s, size %d, compress %d, flags %x", archname, name, hdr.uncompressedsize, hdr.compression, hdr.flags); + if(dbgzip) conoutf("file %s, size %d, compress %d, flags %x", name, hdr.uncompressedsize, hdr.compression, hdr.flags); #endif src += hdr.namelength + hdr.extralength + hdr.commentlength; @@ -420,7 +420,7 @@ struct zipstream : stream { if(reading < 0) return; #ifndef STANDALONE - if(dbgzip) conoutf(info->compressedsize ? "%s: zfile.total_out %d, info->size %d" : "%s: reading %d, info->size %d", info->name, info->compressedsize ? zfile.total_out : reading - info->offset, info->size); + if(dbgzip) conoutf(info->compressedsize ? "%s: zfile.total_out %d, info->size %u" : "%s: reading %d, info->size %u", info->name, int(info->compressedsize ? zfile.total_out : reading - info->offset), info->size); #endif if(info->compressedsize) inflateEnd(&zfile); reading = -1; @@ -538,7 +538,7 @@ struct zipstream : stream else { #ifndef STANDALONE - if(dbgzip) conoutf("inflate error: %s", err); + if(dbgzip) conoutf("inflate error: %d", err); #endif stopreading(); }