From 13a783d4415ffdfaef3e386bd1cb119667fd51c7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 5 Sep 2015 21:47:33 -0700 Subject: [PATCH] Remove UTIL_Format() and UTIL_FormatArgs(). --- core/ChatTriggers.cpp | 6 +++--- core/ConCmdManager.cpp | 6 +++--- core/CoreConfig.cpp | 4 ++-- core/HalfLife2.cpp | 4 ++-- core/MenuManager.cpp | 10 +++++----- core/MenuStyle_Radio.cpp | 4 ++-- core/MenuStyle_Valve.cpp | 2 +- core/NextMap.cpp | 16 ++++++++-------- core/NextMap.h | 7 ++++--- core/PlayerManager.cpp | 22 +++++++++++----------- core/sm_stringutil.cpp | 14 -------------- core/sm_stringutil.h | 2 -- core/smn_keyvalues.cpp | 4 ++-- core/sourcemod.cpp | 8 ++++---- 14 files changed, 47 insertions(+), 62 deletions(-) diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index 350b6350..76022a86 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -306,12 +306,12 @@ void ChatTriggers::OnSayCommand_Pre() char buffer[128]; if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "Flooding the server", &client)) - UTIL_Format(buffer, sizeof(buffer), "You are flooding the server!"); + ke::SafeSprintf(buffer, sizeof(buffer), "You are flooding the server!"); /* :TODO: we should probably kick people who spam too much. */ char fullbuffer[192]; - UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s", buffer); + ke::SafeSprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s", buffer); g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer); m_bWasFloodedMessage = true; @@ -453,7 +453,7 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args) /* Check if we need to prepend sm_ */ if (prepended) { - len = UTIL_Format(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args); + len = ke::SafeSprintf(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args); } else { len = ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args); } diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 386e2900..548569f6 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -348,20 +348,20 @@ bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmi char buffer[128]; if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "No Access", &client)) { - UTIL_Format(buffer, sizeof(buffer), "You do not have access to this command"); + ke::SafeSprintf(buffer, sizeof(buffer), "You do not have access to this command"); } unsigned int replyto = g_ChatTriggers.GetReplyTo(); if (replyto == SM_REPLY_CONSOLE) { char fullbuffer[192]; - UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer); + ke::SafeSprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer); pPlayer->PrintToConsole(fullbuffer); } else if (replyto == SM_REPLY_CHAT) { char fullbuffer[192]; - UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s.", buffer); + ke::SafeSprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s.", buffer); g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer); } diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index ecd29e9a..6869401d 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -483,7 +483,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) if (file_exists) { char cmd[255]; - UTIL_Format(cmd, sizeof(cmd), "exec %s\n", local); + ke::SafeSprintf(cmd, sizeof(cmd), "exec %s\n", local); engine->ServerCommand(cmd); } @@ -538,7 +538,7 @@ void SM_ExecuteForPlugin(IPluginContext *ctx) can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create); } char cmd[255]; - UTIL_Format(cmd, sizeof(cmd), "sm internal 2 %d\n", plugin->GetSerial()); + ke::SafeSprintf(cmd, sizeof(cmd), "sm internal 2 %d\n", plugin->GetSerial()); engine->ServerCommand(cmd); } } diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index f66e22e5..3a03697f 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -500,7 +500,7 @@ bool CHalfLife2::TextMsg(int client, int dest, const char *msg) if (chat_saytext != NULL && strcmp(chat_saytext, "yes") == 0) { char buffer[253]; - UTIL_Format(buffer, sizeof(buffer), "%s\1\n", msg); + ke::SafeSprintf(buffer, sizeof(buffer), "%s\1\n", msg); #if SOURCE_ENGINE == SE_DOTA CUserMsg_SayText *pMsg; @@ -875,7 +875,7 @@ void CHalfLife2::AddDelayedKick(int client, int userid, const char *msg) kick.client = client; kick.userid = userid; - UTIL_Format(kick.buffer, sizeof(kick.buffer), "%s", msg); + ke::SafeSprintf(kick.buffer, sizeof(kick.buffer), "%s", msg); m_DelayedKicks.push(kick); } diff --git a/core/MenuManager.cpp b/core/MenuManager.cpp index fd34df77..498f6f3e 100644 --- a/core/MenuManager.cpp +++ b/core/MenuManager.cpp @@ -446,7 +446,7 @@ skip_search: char text[50]; if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "No Vote", &client)) { - UTIL_Format(text, sizeof(text), "No Vote"); + ke::SafeStrcpy(text, sizeof(text), "No Vote"); } ItemDrawInfo dr(text, 0); position = panel->DrawItem(dr); @@ -606,7 +606,7 @@ skip_search: { if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Back", &client)) { - UTIL_Format(text, sizeof(text), "Back"); + ke::SafeStrcpy(text, sizeof(text), "Back"); } dr.style = ITEMDRAW_CONTROL; position = panel->DrawItem(dr); @@ -616,7 +616,7 @@ skip_search: { if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Previous", &client)) { - UTIL_Format(text, sizeof(text), "Previous"); + ke::SafeStrcpy(text, sizeof(text), "Previous"); } dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL; position = panel->DrawItem(dr); @@ -637,7 +637,7 @@ skip_search: { if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Next", &client)) { - UTIL_Format(text, sizeof(text), "Next"); + ke::SafeStrcpy(text, sizeof(text), "Next"); } dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL; position = panel->DrawItem(dr); @@ -668,7 +668,7 @@ skip_search: { if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Exit", &client)) { - UTIL_Format(text, sizeof(text), "Exit"); + ke::SafeStrcpy(text, sizeof(text), "Exit"); } dr.style = ITEMDRAW_CONTROL; position = panel->DrawItem(dr); diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index 306defd5..4a40e607 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -456,7 +456,7 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text) { if (title[0] != '\0') { - display_len = UTIL_Format(display_pkt, + display_len = ke::SafeSprintf(display_pkt, sizeof(display_pkt), "%s\n%s", title, @@ -464,7 +464,7 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text) } else { - display_len = UTIL_Format(display_pkt, + display_len = ke::SafeSprintf(display_pkt, sizeof(display_pkt), "%s", text); diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index 1072511e..5c4f9af8 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -297,7 +297,7 @@ unsigned int CValveMenuDisplay::DrawItem(const ItemDrawInfo &item) } char buffer[255]; - UTIL_Format(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display); + ke::SafeSprintf(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display); KeyValues *ki = m_pKv->FindKey(g_OptionNumTable[m_NextPos], true); ki->SetString("command", g_OptionCmdTable[m_NextPos]); diff --git a/core/NextMap.cpp b/core/NextMap.cpp index b45cc5c2..59428cd0 100644 --- a/core/NextMap.cpp +++ b/core/NextMap.cpp @@ -147,8 +147,8 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const logger->LogMessage("[SM] Changed map to \"%s\"", newmap); - UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap); - UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change"); + ke::SafeSprintf(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap); + ke::SafeSprintf(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change"); #if SOURCE_ENGINE != SE_DARKMESSIAH RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown)); @@ -171,7 +171,7 @@ void NextMapManager::OnSourceModLevelChange( const char *mapName ) { /* Something intercepted the mapchange */ char newReason[255]; - UTIL_Format(newReason, sizeof(newReason), "%s (Map overridden)", m_tempChangeInfo.m_changeReason); + ke::SafeSprintf(newReason, sizeof(newReason), "%s (Map overridden)", m_tempChangeInfo.m_changeReason); m_mapHistory.push_back(new MapChangeData(lastMap, newReason, m_tempChangeInfo.startTime)); } @@ -193,14 +193,14 @@ void NextMapManager::OnSourceModLevelChange( const char *mapName ) m_tempChangeInfo.m_mapName[0] ='\0'; m_tempChangeInfo.m_changeReason[0] = '\0'; m_tempChangeInfo.startTime = time(NULL); - UTIL_Format(lastMap, sizeof(lastMap), "%s", mapName); + ke::SafeSprintf(lastMap, sizeof(lastMap), "%s", mapName); } void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeReason ) { /* Store the mapname and reason */ - UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), "%s", mapName); - UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "%s", changeReason); + ke::SafeSprintf(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), "%s", mapName); + ke::SafeSprintf(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "%s", changeReason); /* Change level and skip our hook */ g_forcedChange = true; @@ -233,7 +233,7 @@ void CmdChangeLevelCallback() if (g_NextMap.m_tempChangeInfo.m_mapName[0] == '\0') { - UTIL_Format(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1)); - UTIL_Format(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command"); + ke::SafeSprintf(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1)); + ke::SafeSprintf(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command"); } } diff --git a/core/NextMap.h b/core/NextMap.h index 7ebd8c7f..c98cd3d4 100644 --- a/core/NextMap.h +++ b/core/NextMap.h @@ -33,16 +33,17 @@ #define _INCLUDE_SOURCEMOD_NEXTMAP_H_ #include "sm_globals.h" -#include "eiface.h" +#include #include "sh_list.h" #include "sm_stringutil.h" +#include struct MapChangeData { MapChangeData(const char *mapName, const char *changeReason, time_t time) { - UTIL_Format(m_mapName, sizeof(m_mapName), mapName); - UTIL_Format(m_changeReason, sizeof(m_changeReason), changeReason); + ke::SafeStrcpy(m_mapName, sizeof(m_mapName), mapName); + ke::SafeStrcpy(m_changeReason, sizeof(m_changeReason), changeReason); startTime = time; } diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 55448251..d9b3d701 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -290,7 +290,7 @@ ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key, } else if (strcasecmp(value, "off") == 0) { m_QueryLang = false; } else { - UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\""); + ke::SafeSprintf(error, maxlength, "Invalid value: must be \"on\" or \"off\""); return ConfigResult_Reject; } return ConfigResult_Accept; @@ -301,7 +301,7 @@ ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key, } else if ( strcasecmp(value, "no") == 0) { m_bAuthstringValidation = false; } else { - UTIL_Format(error, maxlength, "Invalid value: must be \"yes\" or \"no\""); + ke::SafeSprintf(error, maxlength, "Invalid value: must be \"yes\" or \"no\""); return ConfigResult_Reject; } return ConfigResult_Accept; @@ -1001,21 +1001,21 @@ void ListExtensionsToClient(CPlayer *player, const CCommand &args) const char *author = api->GetExtensionAuthor(); const char *description = api->GetExtensionDescription(); - size_t len = UTIL_Format(buffer, sizeof(buffer), " \"%s\"", name); + size_t len = ke::SafeSprintf(buffer, sizeof(buffer), " \"%s\"", name); if (version != NULL && version[0]) { - len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", version); + len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " (%s)", version); } if (author != NULL && author[0]) { - len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", author); + len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " by %s", author); } if (description != NULL && description[0]) { - len += UTIL_Format(&buffer[len], sizeof(buffer)-len, ": %s", description); + len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, ": %s", description); } @@ -1082,18 +1082,18 @@ void ListPluginsToClient(CPlayer *player, const CCommand &args) size_t len; const sm_plugininfo_t *info = pl->GetPublicInfo(); - len = UTIL_Format(buffer, sizeof(buffer), " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); + len = ke::SafeSprintf(buffer, sizeof(buffer), " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); if (IS_STR_FILLED(info->version)) { - len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", info->version); + len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " (%s)", info->version); } if (IS_STR_FILLED(info->author)) { - UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", info->author); + ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " by %s", info->author); } else { - UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", pl->GetFilename()); + ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " %s", pl->GetFilename()); } ClientConsolePrint(e, "%s", buffer); } @@ -2434,7 +2434,7 @@ void CPlayer::Kick(const char *str) if (userid > 0) { char buffer[255]; - UTIL_Format(buffer, sizeof(buffer), "kickid %d %s\n", userid, str); + ke::SafeSprintf(buffer, sizeof(buffer), "kickid %d %s\n", userid, str); engine->ServerCommand(buffer); } } diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index ddc8eea4..895e42a1 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -41,20 +41,6 @@ #include #include -size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - size_t len = ke::SafeVsprintf(buffer, maxlength, fmt, ap); - va_end(ap); - return len; -} - -size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap) -{ - return ke::SafeVsprintf(buffer, maxlength, fmt, ap); -} - char *sm_strdup(const char *str) { char *ptr = new char[strlen(str)+1]; diff --git a/core/sm_stringutil.h b/core/sm_stringutil.h index 3ea0e560..b1433fa3 100644 --- a/core/sm_stringutil.h +++ b/core/sm_stringutil.h @@ -42,8 +42,6 @@ using namespace SourceMod; #define IS_STR_FILLED(var) (var[0] != '\0') -size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); -size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap); char *sm_strdup(const char *str); char *UTIL_ToLowerCase(const char *str); diff --git a/core/smn_keyvalues.cpp b/core/smn_keyvalues.cpp index f420c5b1..34d1ce33 100644 --- a/core/smn_keyvalues.cpp +++ b/core/smn_keyvalues.cpp @@ -266,7 +266,7 @@ static cell_t smn_KvSetVector(IPluginContext *pCtx, const cell_t *params) pCtx->LocalToStringNULL(params[2], &key); pCtx->LocalToPhysAddr(params[3], &vector); - UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(vector[0]), sp_ctof(vector[1]), sp_ctof(vector[2])); + ke::SafeSprintf(buffer, sizeof(buffer), "%f %f %f", sp_ctof(vector[0]), sp_ctof(vector[1]), sp_ctof(vector[2])); pStk->pCurRoot.front()->SetString(key, buffer); @@ -437,7 +437,7 @@ static cell_t smn_KvGetVector(IPluginContext *pCtx, const cell_t *params) pCtx->LocalToPhysAddr(params[3], &outvector); pCtx->LocalToPhysAddr(params[4], &defvector); - UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(defvector[0]), sp_ctof(defvector[1]), sp_ctof(defvector[2])); + ke::SafeSprintf(buffer, sizeof(buffer), "%f %f %f", sp_ctof(defvector[0]), sp_ctof(defvector[1]), sp_ctof(defvector[2])); value = pStk->pCurRoot.front()->GetString(key, buffer); diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 6b1f6a70..52d231fb 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -105,7 +105,7 @@ ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, { if (source == ConfigSource_Console) { - UTIL_Format(error, maxlength, "Cannot be set at runtime"); + ke::SafeSprintf(error, maxlength, "Cannot be set at runtime"); return ConfigResult_Reject; } @@ -193,7 +193,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late { if (error && maxlength) { - UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", + ke::SafeSprintf(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", myerror, PLATFORM_LIB_EXT); } @@ -428,7 +428,7 @@ void SourceModBase::DoGlobalPluginLoads() if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL) { char path[PLATFORM_MAX_PATH]; - UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext); + ke::SafeSprintf(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext); extsys->LoadAutoExtension(path); } @@ -709,7 +709,7 @@ size_t SourceModBase::FormatArgs(char *buffer, const char *fmt, va_list ap) { - return UTIL_FormatArgs(buffer, maxlength, fmt, ap); + return ke::SafeVsprintf(buffer, maxlength, fmt, ap); } void SourceModBase::AddFrameAction(FRAMEACTION fn, void *data)