From 06f59e0559fa622270b84b5bebb31e482ebdf41e Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 21 Aug 2015 15:51:36 +0200 Subject: [PATCH] use safe strings (cleanup) --- source/src/client.cpp | 2 +- source/src/clientgame.cpp | 8 +++----- source/src/rendermodel.cpp | 4 ++-- source/src/serverbrowser.cpp | 6 ++---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 15ac2307..d60c459a 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -1062,7 +1062,7 @@ double dlpackage(package *pck) const char *tmpname = findfile("tmp", "wb"); FILE *outfile = fopen(tmpname, "wb"); string req, pckname = ""; - sprintf(req, "%s/%s%s", pck->source->addr, strreplace(pckname, pck->name, " ", "%20"), (pck->type==PCK_MAP || pck->type==PCK_MAPMODEL || pck->type==PCK_SKYBOX) ? ".zip" : ""); + formatstring(req)("%s/%s%s", pck->source->addr, strreplace(pckname, pck->name, " ", "%20"), (pck->type==PCK_MAP || pck->type==PCK_MAPMODEL || pck->type==PCK_SKYBOX) ? ".zip" : ""); conoutf("downloading %s from %s ...", pck->name, pck->source->addr); if(!outfile) { diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index c5f120a4..6c21e0aa 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -326,7 +326,7 @@ void teaminfo(const char *team, const char *attr) int t_deaths = 0; int t_points = 0; - string teammembers = "", tmp; + string teammembers = ""; loopv(players) if(players[i] && players[i]->team == t) { @@ -334,8 +334,7 @@ void teaminfo(const char *team, const char *attr) t_deaths += players[i]->deaths; t_points += players[i]->points; t_flags += players[i]->flagscore; - sprintf(tmp, "%s%d ", teammembers, players[i]->clientnum); - concatstring(teammembers, tmp); + concatformatstring(teammembers, "%d ", players[i]->clientnum); } loopv(discscores) if(discscores[i].team == t) @@ -352,8 +351,7 @@ void teaminfo(const char *team, const char *attr) t_deaths += player1->deaths; t_points += player1->points; t_flags += player1->flagscore; - sprintf(tmp, "%s%d ", teammembers, player1->clientnum); - concatstring(teammembers, tmp); + concatformatstring(teammembers, "%d ", player1->clientnum); } ATTR_INT(flags, t_flags); diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index ede3e1af..21350eac 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -778,9 +778,9 @@ void preload_entmodels() defformatstring(widn)("modmdlpickup%d", i-3); if (identexists(widn)) - strcat(buf, getalias(widn)); + concatstring(buf, getalias(widn)); else - strcat(buf, entmdlnames[i]); + concatstring(buf, entmdlnames[i]); model *mdl = loadmodel(buf); diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index 46c3bece..cb0f00df 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -1333,8 +1333,7 @@ void retrieveservers(vector &data) CURL *curl = curl_easy_init(); char *pname = curl_easy_escape(curl, global_name, 0); - string request; - sprintf(request, "http://%s/retrieve.do?action=list&name=%s&version=%d&build=%d", mastername, pname, AC_VERSION, getbuildtype()|(1<<16)); + defformatstring(request)("http://%s/retrieve.do?action=list&name=%s&version=%d&build=%d", mastername, pname, AC_VERSION, getbuildtype()|(1<<16)); curl_free(pname); const char *tmpname = findfile(path("config/servers.cfg", true), "wb"); @@ -1397,8 +1396,7 @@ void retrieveservers(vector &data) defformatstring(text)("retrieving servers from %s:%d... (esc to abort)", mastername, masterport); show_out_of_renderloop_progress(0, text); int starttime = SDL_GetTicks(), timeout = 0; - string request; - sprintf(request, "list %s %d %d\n",global_name,AC_VERSION,getbuildtype()); + defformatstring(request)("list %s %d %d\n", global_name, AC_VERSION, getbuildtype()); const char *req = request; int reqlen = strlen(req); ENetBuffer buf;