Merge pull request #379 from alliedmodders/rm-format

Remove Format/FormatArgs from the core/logic bridge.
This commit is contained in:
David Anderson 2015-08-30 21:04:20 -04:00
commit 3786a2756b
16 changed files with 88 additions and 98 deletions

View File

@ -33,6 +33,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "DebugReporter.h" #include "DebugReporter.h"
#include "Logger.h" #include "Logger.h"
#include <am-string.h>
DebugReport g_DbgReporter; DebugReport g_DbgReporter;
@ -47,7 +48,7 @@ void DebugReport::OnDebugSpew(const char *msg, ...)
char buffer[512]; char buffer[512];
va_start(ap, msg); va_start(ap, msg);
smcore.FormatArgs(buffer, sizeof(buffer), msg, ap); ke::SafeVsprintf(buffer, sizeof(buffer), msg, ap);
va_end(ap); va_end(ap);
g_Logger.LogMessage("[SM] %s", buffer); g_Logger.LogMessage("[SM] %s", buffer);
@ -65,7 +66,7 @@ void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, c
void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap) void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap)
{ {
char buffer[512]; char buffer[512];
smcore.FormatArgs(buffer, sizeof(buffer), message, ap); ke::SafeVsprintf(buffer, sizeof(buffer), message, ap);
const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename(); const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
const char *error = g_pSourcePawn2->GetErrorString(err); const char *error = g_pSourcePawn2->GetErrorString(err);
@ -99,7 +100,7 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr
char buffer[512]; char buffer[512];
va_start(ap, message); va_start(ap, message);
smcore.FormatArgs(buffer, sizeof(buffer), message, ap); ke::SafeVsprintf(buffer, sizeof(buffer), message, ap);
va_end(ap); va_end(ap);
const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename(); const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename();

View File

@ -36,6 +36,7 @@
#include "common_logic.h" #include "common_logic.h"
#include "PluginSys.h" #include "PluginSys.h"
#include <am-utility.h> #include <am-utility.h>
#include <am-string.h>
CExtensionManager g_Extensions; CExtensionManager g_Extensions;
IdentityType_t g_ExtType; IdentityType_t g_ExtType;
@ -567,7 +568,7 @@ void CExtensionManager::TryAutoload()
} }
char file[PLATFORM_MAX_PATH]; char file[PLATFORM_MAX_PATH];
len = smcore.Format(file, sizeof(file), "%s", lfile); len = ke::SafeSprintf(file, sizeof(file), "%s", lfile);
strcpy(&file[len - 9], ".ext"); strcpy(&file[len - 9], ".ext");
LoadAutoExtension(file); LoadAutoExtension(file);
@ -583,7 +584,7 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOn
if (strcmp(ext, PLATFORM_LIB_EXT) == 0) if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
{ {
char path2[PLATFORM_MAX_PATH]; char path2[PLATFORM_MAX_PATH];
smcore.Format(path2, sizeof(path2), "%s", path); ke::SafeSprintf(path2, sizeof(path2), "%s", path);
path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0'; path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
return LoadAutoExtension(path2, bErrorOnMissing); return LoadAutoExtension(path2, bErrorOnMissing);
} }
@ -675,7 +676,7 @@ IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size
if (strcmp(ext, PLATFORM_LIB_EXT) == 0) if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
{ {
char path2[PLATFORM_MAX_PATH]; char path2[PLATFORM_MAX_PATH];
smcore.Format(path2, sizeof(path2), "%s", file); ke::SafeSprintf(path2, sizeof(path2), "%s", file);
path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0'; path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
return LoadExtension(path2, error, maxlength); return LoadExtension(path2, error, maxlength);
} }
@ -993,7 +994,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand
char path[PLATFORM_MAX_PATH]; char path[PLATFORM_MAX_PATH];
char error[256]; char error[256];
smcore.Format(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "", ke::SafeSprintf(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "",
!strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : ""); !strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : "");
if (FindExtensionByFile(path) != NULL) if (FindExtensionByFile(path) != NULL)

View File

@ -42,6 +42,7 @@
#include "common_logic.h" #include "common_logic.h"
#include "sm_crc32.h" #include "sm_crc32.h"
#include "MemoryUtils.h" #include "MemoryUtils.h"
#include <am-string.h>
#if defined PLATFORM_POSIX #if defined PLATFORM_POSIX
#include <dlfcn.h> #include <dlfcn.h>
@ -271,7 +272,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
error[0] = '\0'; error[0] = '\0';
if (strcmp(name, "server") != 0) if (strcmp(name, "server") != 0)
{ {
smcore.Format(error, sizeof(error), "Unrecognized library \"%s\"", name); ke::SafeSprintf(error, sizeof(error), "Unrecognized library \"%s\"", name);
} }
else if (!s_ServerBinCRC_Ok) else if (!s_ServerBinCRC_Ok)
{ {
@ -281,7 +282,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
g_pSM->BuildPath(Path_Game, path, sizeof(path), "bin/" PLATFORM_SERVER_BINARY); g_pSM->BuildPath(Path_Game, path, sizeof(path), "bin/" PLATFORM_SERVER_BINARY);
if ((fp = fopen(path, "rb")) == NULL) if ((fp = fopen(path, "rb")) == NULL)
{ {
smcore.Format(error, sizeof(error), "Could not open binary: %s", path); ke::SafeSprintf(error, sizeof(error), "Could not open binary: %s", path);
} else { } else {
size_t size; size_t size;
void *buffer; void *buffer;
@ -791,7 +792,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
if (!libsys->PathExists(path)) if (!libsys->PathExists(path))
{ {
/* Nope, use the old mechanism. */ /* Nope, use the old mechanism. */
smcore.Format(path, sizeof(path), "%s.txt", m_File); ke::SafeSprintf(path, sizeof(path), "%s.txt", m_File);
if (!EnterFile(path, error, maxlength)) if (!EnterFile(path, error, maxlength))
{ {
return false; return false;
@ -801,7 +802,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
g_pSM->BuildPath(Path_SM, path, sizeof(path), "gamedata/custom/%s.txt", m_File); g_pSM->BuildPath(Path_SM, path, sizeof(path), "gamedata/custom/%s.txt", m_File);
if (libsys->PathExists(path)) if (libsys->PathExists(path))
{ {
smcore.Format(path, sizeof(path), "custom/%s.txt", m_File); ke::SafeSprintf(path, sizeof(path), "custom/%s.txt", m_File);
return EnterFile(path, error, maxlength); return EnterFile(path, error, maxlength);
} }
return true; return true;
@ -841,7 +842,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
List<String>::iterator iter; List<String>::iterator iter;
for (iter = fileList.begin(); iter != fileList.end(); iter++) for (iter = fileList.begin(); iter != fileList.end(); iter++)
{ {
smcore.Format(path, sizeof(path), "%s/%s", m_File, (*iter).c_str()); ke::SafeSprintf(path, sizeof(path), "%s/%s", m_File, (*iter).c_str());
if (!EnterFile(path, error, maxlength)) if (!EnterFile(path, error, maxlength))
{ {
return false; return false;
@ -875,7 +876,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
continue; continue;
} }
smcore.Format(path, sizeof(path), "%s/custom/%s", m_File, curFile); ke::SafeSprintf(path, sizeof(path), "%s/custom/%s", m_File, curFile);
if (!EnterFile(path, error, maxlength)) if (!EnterFile(path, error, maxlength))
{ {
libsys->CloseDirectory(customDir); libsys->CloseDirectory(customDir);

View File

@ -36,6 +36,7 @@
#include "ShareSys.h" #include "ShareSys.h"
#include "ExtensionSys.h" #include "ExtensionSys.h"
#include "PluginSys.h" #include "PluginSys.h"
#include <am-string.h>
HandleSystem g_HandleSys; HandleSystem g_HandleSys;
@ -1144,7 +1145,7 @@ void HandleSystem::Dump(HANDLE_REPORTER rep)
else else
{ {
char buffer[32]; char buffer[32];
smcore.Format(buffer, sizeof(buffer), "%d", size); ke::SafeSprintf(buffer, sizeof(buffer), "%d", size);
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer); rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
total_size += size; total_size += size;
} }

View File

@ -34,6 +34,7 @@
#include "Logger.h" #include "Logger.h"
#include <sourcemod_version.h> #include <sourcemod_version.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <am-string.h>
Logger g_Logger; Logger g_Logger;
@ -57,7 +58,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key,
} else if (strcasecmp(value, "off") == 0) { } else if (strcasecmp(value, "off") == 0) {
state = false; state = false;
} else { } else {
smcore.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_Reject;
} }
@ -78,7 +79,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key,
} else if (strcasecmp(value, "game") == 0) { } else if (strcasecmp(value, "game") == 0) {
m_Mode = LoggingMode_Game; m_Mode = LoggingMode_Game;
} else { } else {
smcore.Format(error, maxlength, "Invalid value: must be [daily|map|game]"); ke::SafeSprintf(error, maxlength, "Invalid value: must be [daily|map|game]");
return ConfigResult_Reject; return ConfigResult_Reject;
} }
@ -264,7 +265,7 @@ void Logger::LogToOpenFileEx(FILE *fp, const char *msg, va_list ap)
static ConVar *sv_logecho = smcore.FindConVar("sv_logecho"); static ConVar *sv_logecho = smcore.FindConVar("sv_logecho");
char buffer[3072]; char buffer[3072];
smcore.FormatArgs(buffer, sizeof(buffer), msg, ap); ke::SafeVsprintf(buffer, sizeof(buffer), msg, ap);
char date[32]; char date[32];
time_t t = g_pSM->GetAdjustedTime(); time_t t = g_pSM->GetAdjustedTime();
@ -276,7 +277,7 @@ void Logger::LogToOpenFileEx(FILE *fp, const char *msg, va_list ap)
if (!sv_logecho || smcore.GetCvarBool(sv_logecho)) if (!sv_logecho || smcore.GetCvarBool(sv_logecho))
{ {
static char conBuffer[4096]; static char conBuffer[4096];
smcore.Format(conBuffer, sizeof(conBuffer), "L %s: %s\n", date, buffer); ke::SafeSprintf(conBuffer, sizeof(conBuffer), "L %s: %s\n", date, buffer);
smcore.ConPrint(conBuffer); smcore.ConPrint(conBuffer);
} }
} }
@ -289,7 +290,7 @@ void Logger::LogToFileOnlyEx(FILE *fp, const char *msg, va_list ap)
} }
char buffer[3072]; char buffer[3072];
smcore.FormatArgs(buffer, sizeof(buffer), msg, ap); ke::SafeVsprintf(buffer, sizeof(buffer), msg, ap);
char date[32]; char date[32];
time_t t = g_pSM->GetAdjustedTime(); time_t t = g_pSM->GetAdjustedTime();

View File

@ -32,6 +32,7 @@
#include "common_logic.h" #include "common_logic.h"
#include "PhraseCollection.h" #include "PhraseCollection.h"
#include "Translator.h" #include "Translator.h"
#include <am-string.h>
CPhraseCollection::CPhraseCollection() CPhraseCollection::CPhraseCollection()
{ {
@ -54,7 +55,7 @@ IPhraseFile *CPhraseCollection::AddPhraseFile(const char *filename)
char full_name[PLATFORM_MAX_PATH]; char full_name[PLATFORM_MAX_PATH];
/* No compat shim here. The user should have read the doc. */ /* No compat shim here. The user should have read the doc. */
smcore.Format(full_name, sizeof(full_name), "%s.txt", filename); ke::SafeSprintf(full_name, sizeof(full_name), "%s.txt", filename);
fid = g_Translator.FindOrAddPhraseFile(full_name); fid = g_Translator.FindOrAddPhraseFile(full_name);
pFile = g_Translator.GetFileByIndex(fid); pFile = g_Translator.GetFileByIndex(fid);

View File

@ -43,6 +43,7 @@
#include "common_logic.h" #include "common_logic.h"
#include "Translator.h" #include "Translator.h"
#include "Logger.h" #include "Logger.h"
#include <am-string.h>
CPluginManager g_PluginSys; CPluginManager g_PluginSys;
HandleType_t g_PluginType = 0; HandleType_t g_PluginType = 0;
@ -58,7 +59,7 @@ CPlugin::CPlugin(const char *file)
m_serial = ++MySerial; m_serial = ++MySerial;
m_pRuntime = NULL; m_pRuntime = NULL;
m_errormsg[sizeof(m_errormsg) - 1] = '\0'; m_errormsg[sizeof(m_errormsg) - 1] = '\0';
smcore.Format(m_filename, sizeof(m_filename), "%s", file); ke::SafeSprintf(m_filename, sizeof(m_filename), "%s", file);
m_handle = 0; m_handle = 0;
m_ident = NULL; m_ident = NULL;
m_FakeNativesMissing = false; m_FakeNativesMissing = false;
@ -157,7 +158,7 @@ CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
{ {
if (error) if (error)
{ {
smcore.Format(error, maxlength, "Unable to open file"); ke::SafeSprintf(error, maxlength, "Unable to open file");
} }
pPlugin->m_status = Plugin_BadLoad; pPlugin->m_status = Plugin_BadLoad;
return pPlugin; return pPlugin;
@ -211,7 +212,7 @@ void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
va_list ap; va_list ap;
va_start(ap, error_fmt); va_start(ap, error_fmt);
smcore.FormatArgs(m_errormsg, sizeof(m_errormsg), error_fmt, ap); ke::SafeVsprintf(m_errormsg, sizeof(m_errormsg), error_fmt, ap);
va_end(ap); va_end(ap);
if (m_pRuntime != NULL) if (m_pRuntime != NULL)
@ -278,7 +279,7 @@ bool CPlugin::UpdateInfo()
{ {
base->LocalToString(info->date, (char **)&pDate); base->LocalToString(info->date, (char **)&pDate);
base->LocalToString(info->time, (char **)&pTime); base->LocalToString(info->time, (char **)&pTime);
smcore.Format(m_DateTime, sizeof(m_DateTime), "%s %s", pDate, pTime); ke::SafeSprintf(m_DateTime, sizeof(m_DateTime), "%s %s", pDate, pTime);
} }
if (m_FileVersion > 5) if (m_FileVersion > 5)
{ {
@ -867,7 +868,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
if (localpath == NULL) if (localpath == NULL)
{ {
/* If no path yet, don't add a former slash */ /* If no path yet, don't add a former slash */
smcore.Format(new_local, sizeof(new_local), "%s", dir->GetEntryName()); ke::SafeSprintf(new_local, sizeof(new_local), "%s", dir->GetEntryName());
} else { } else {
libsys->PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName()); libsys->PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName());
} }
@ -882,7 +883,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
char plugin[PLATFORM_MAX_PATH]; char plugin[PLATFORM_MAX_PATH];
if (localpath == NULL) if (localpath == NULL)
{ {
smcore.Format(plugin, sizeof(plugin), "%s", name); ke::SafeSprintf(plugin, sizeof(plugin), "%s", name);
} else { } else {
libsys->PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name); libsys->PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name);
} }
@ -936,14 +937,14 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
pPlugin->m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg)); pPlugin->m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg));
if (!pPlugin->m_pRuntime) { if (!pPlugin->m_pRuntime) {
if (error) if (error)
smcore.Format(error, maxlength, "Unable to load plugin (%s)", loadmsg); ke::SafeSprintf(error, maxlength, "Unable to load plugin (%s)", loadmsg);
pPlugin->m_status = Plugin_BadLoad; pPlugin->m_status = Plugin_BadLoad;
} else { } else {
if (pPlugin->UpdateInfo()) { if (pPlugin->UpdateInfo()) {
pPlugin->m_status = Plugin_Created; pPlugin->m_status = Plugin_Created;
} else { } else {
if (error) if (error)
smcore.Format(error, maxlength, "%s", pPlugin->m_errormsg); ke::SafeSprintf(error, maxlength, "%s", pPlugin->m_errormsg);
} }
} }
} }
@ -953,9 +954,9 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
unsigned char *pCodeHash = pPlugin->m_pRuntime->GetCodeHash(); unsigned char *pCodeHash = pPlugin->m_pRuntime->GetCodeHash();
char codeHashBuf[40]; char codeHashBuf[40];
smcore.Format(codeHashBuf, 40, "plugin_"); ke::SafeSprintf(codeHashBuf, 40, "plugin_");
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
smcore.Format(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]); ke::SafeSprintf(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]);
const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf); const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf);
if (bulletinUrl != NULL) if (bulletinUrl != NULL)
@ -966,9 +967,9 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
{ {
if (bulletinUrl[0] != '\0') if (bulletinUrl[0] != '\0')
{ {
smcore.Format(error, maxlength, "Known malware detected and blocked. See %s for more info", bulletinUrl); ke::SafeSprintf(error, maxlength, "Known malware detected and blocked. See %s for more info", bulletinUrl);
} else { } else {
smcore.Format(error, maxlength, "Possible malware or illegal plugin detected and blocked"); ke::SafeSprintf(error, maxlength, "Possible malware or illegal plugin detected and blocked");
} }
} }
pPlugin->m_status = Plugin_BadLoad; pPlugin->m_status = Plugin_BadLoad;
@ -1045,11 +1046,11 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
{ {
if (m_LoadingLocked) if (m_LoadingLocked)
{ {
smcore.Format(error, maxlength, "There is a global plugin loading lock in effect"); ke::SafeSprintf(error, maxlength, "There is a global plugin loading lock in effect");
} }
else else
{ {
smcore.Format(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)"); ke::SafeSprintf(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)");
} }
} }
return NULL; return NULL;
@ -1171,13 +1172,13 @@ bool CPluginManager::FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size
{ {
IPluginFunction *pFunc; IPluginFunction *pFunc;
char buffer[64]; char buffer[64];
smcore.Format(buffer, sizeof(buffer), "__pl_%s_SetNTVOptional", &pubvar->name[5]); ke::SafeSprintf(buffer, sizeof(buffer), "__pl_%s_SetNTVOptional", &pubvar->name[5]);
if ((pFunc=pBase->GetFunctionByName(buffer))) if ((pFunc=pBase->GetFunctionByName(buffer)))
{ {
cell_t res; cell_t res;
if (pFunc->Execute(&res) != SP_ERROR_NONE) { if (pFunc->Execute(&res) != SP_ERROR_NONE) {
if (error) if (error)
smcore.Format(error, maxlength, "Fatal error during initializing plugin load"); ke::SafeSprintf(error, maxlength, "Fatal error during initializing plugin load");
return false; return false;
} }
} }
@ -1209,7 +1210,7 @@ bool CPluginManager::FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size
{ {
if (error) if (error)
{ {
smcore.Format(error, maxlength, "Could not find required plugin \"%s\"", name); ke::SafeSprintf(error, maxlength, "Could not find required plugin \"%s\"", name);
} }
return false; return false;
} }
@ -1281,7 +1282,7 @@ bool CPluginManager::LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass
{ {
if (error) if (error)
{ {
smcore.Format(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", name, file); ke::SafeSprintf(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", name, file);
} }
return false; return false;
} }
@ -1294,14 +1295,14 @@ bool CPluginManager::LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass
{ {
IPluginFunction *pFunc; IPluginFunction *pFunc;
char buffer[64]; char buffer[64];
smcore.Format(buffer, sizeof(buffer), "__ext_%s_SetNTVOptional", &pubvar->name[6]); ke::SafeSprintf(buffer, sizeof(buffer), "__ext_%s_SetNTVOptional", &pubvar->name[6]);
if ((pFunc = pBase->GetFunctionByName(buffer)) != NULL) if ((pFunc = pBase->GetFunctionByName(buffer)) != NULL)
{ {
cell_t res; cell_t res;
if (pFunc->Execute(&res) != SP_ERROR_NONE) { if (pFunc->Execute(&res) != SP_ERROR_NONE) {
if (error) if (error)
smcore.Format(error, maxlength, "Fatal error during plugin initialization (ext req)"); ke::SafeSprintf(error, maxlength, "Fatal error during plugin initialization (ext req)");
return false; return false;
} }
} }
@ -1343,7 +1344,7 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
{ {
if (error) if (error)
{ {
smcore.Format(error, maxlength, "Native \"%s\" was not found", native->name); ke::SafeSprintf(error, maxlength, "Native \"%s\" was not found", native->name);
} }
return false; return false;
} }
@ -1489,7 +1490,7 @@ bool CPluginManager::UnloadPlugin(IPlugin *plugin)
if (pContext != NULL && pContext->IsInExec()) if (pContext != NULL && pContext->IsInExec())
{ {
char buffer[255]; char buffer[255];
smcore.Format(buffer, sizeof(buffer), "sm plugins unload %s\n", plugin->GetFilename()); ke::SafeSprintf(buffer, sizeof(buffer), "sm plugins unload %s\n", plugin->GetFilename());
engine->ServerCommand(buffer); engine->ServerCommand(buffer);
return false; return false;
} }
@ -1853,7 +1854,7 @@ ConfigResult CPluginManager::OnSourceModConfigChanged(const char *key,
} else if (strcasecmp(value, "no") == 0) { } else if (strcasecmp(value, "no") == 0) {
m_bBlockBadPlugins = false; m_bBlockBadPlugins = false;
} else { } else {
smcore.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_Reject;
} }
return ConfigResult_Accept; return ConfigResult_Accept;
@ -1974,7 +1975,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
const sm_plugininfo_t *info = pl->GetPublicInfo(); const sm_plugininfo_t *info = pl->GetPublicInfo();
if (pl->GetStatus() != Plugin_Running && !pl->IsSilentlyFailed()) if (pl->GetStatus() != Plugin_Running && !pl->IsSilentlyFailed())
{ {
len += smcore.Format(buffer, sizeof(buffer), " %02d <%s>", id, GetStatusText(pl->GetStatus())); len += ke::SafeSprintf(buffer, sizeof(buffer), " %02d <%s>", id, GetStatusText(pl->GetStatus()));
if (pl->GetStatus() <= Plugin_Error) if (pl->GetStatus() <= Plugin_Error)
{ {
@ -1984,25 +1985,25 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
} }
else else
{ {
len += smcore.Format(buffer, sizeof(buffer), " %02d", id); len += ke::SafeSprintf(buffer, sizeof(buffer), " %02d", id);
} }
if (pl->GetStatus() < Plugin_Created) if (pl->GetStatus() < Plugin_Created)
{ {
if (pl->IsSilentlyFailed()) if (pl->IsSilentlyFailed())
len += smcore.Format(&buffer[len], sizeof(buffer)-len, " Disabled:"); len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " Disabled:");
len += smcore.Format(&buffer[len], sizeof(buffer)-len, " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename());
if (IS_STR_FILLED(info->version)) if (IS_STR_FILLED(info->version))
{ {
len += smcore.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)) if (IS_STR_FILLED(info->author))
{ {
smcore.Format(&buffer[len], sizeof(buffer)-len, " by %s", info->author); ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " by %s", info->author);
} }
} }
else else
{ {
smcore.Format(&buffer[len], sizeof(buffer)-len, " %s", pl->m_filename); ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " %s", pl->m_filename);
} }
rootmenu->ConsolePrint("%s", buffer); rootmenu->ConsolePrint("%s", buffer);
} }
@ -2099,11 +2100,11 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
if (pl->GetStatus() < Plugin_Created) if (pl->GetStatus() < Plugin_Created)
{ {
const sm_plugininfo_t *info = pl->GetPublicInfo(); const sm_plugininfo_t *info = pl->GetPublicInfo();
smcore.Format(name, sizeof(name), (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); ke::SafeSprintf(name, sizeof(name), (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename());
} }
else else
{ {
smcore.Format(name, sizeof(name), "%s", pl->GetFilename()); ke::SafeSprintf(name, sizeof(name), "%s", pl->GetFilename());
} }
if (UnloadPlugin(pl)) if (UnloadPlugin(pl))
@ -2252,7 +2253,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
char combinedHash[33]; char combinedHash[33];
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
smcore.Format(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]); ke::SafeSprintf(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]);
rootmenu->ConsolePrint(" Hash: %s", combinedHash); rootmenu->ConsolePrint(" Hash: %s", combinedHash);
} }
@ -2570,7 +2571,7 @@ SMPlugin *CPluginManager::FindPluginByConsoleArg(const char *arg)
{ {
char pluginfile[256]; char pluginfile[256];
const char *ext = libsys->GetFileExtension(arg) ? "" : ".smx"; const char *ext = libsys->GetFileExtension(arg) ? "" : ".smx";
smcore.Format(pluginfile, sizeof(pluginfile), "%s%s", arg, ext); ke::SafeSprintf(pluginfile, sizeof(pluginfile), "%s%s", arg, ext);
if (!m_LoadLookup.retrieve(pluginfile, &pl)) if (!m_LoadLookup.retrieve(pluginfile, &pl))
return NULL; return NULL;

View File

@ -27,6 +27,7 @@
#include "ProfileTools.h" #include "ProfileTools.h"
#include <stdarg.h> #include <stdarg.h>
#include <am-string.h>
ProfileToolManager g_ProfileToolManager; ProfileToolManager g_ProfileToolManager;
@ -65,7 +66,7 @@ render_help(const char *fmt, ...)
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
smcore.FormatArgs(buffer, sizeof(buffer), fmt, ap); ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap); va_end(ap);
rootmenu->ConsolePrint("%s", buffer); rootmenu->ConsolePrint("%s", buffer);

View File

@ -1,5 +1,5 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 sw=4 tw=99 noet :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
@ -37,6 +37,7 @@
#include <assert.h> #include <assert.h>
#include "TextParsers.h" #include "TextParsers.h"
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include <am-string.h>
TextParsers g_TextParser; TextParsers g_TextParser;
ITextParsers *textparsers = &g_TextParser; ITextParsers *textparsers = &g_TextParser;
@ -134,7 +135,7 @@ SMCError TextParsers::ParseSMCFile(const char *file,
states->col = 0; states->col = 0;
} }
libsys->GetPlatformError(error, sizeof(error)); libsys->GetPlatformError(error, sizeof(error));
smcore.Format(buffer, maxsize, "File could not be opened: %s", error); ke::SafeSprintf(buffer, maxsize, "File could not be opened: %s", error);
return SMCError_StreamOpen; return SMCError_StreamOpen;
} }
@ -143,7 +144,7 @@ SMCError TextParsers::ParseSMCFile(const char *file,
fclose(fp); fclose(fp);
errstr = GetSMCErrorString(result); errstr = GetSMCErrorString(result);
smcore.Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); ke::SafeSprintf(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
return result; return result;
} }
@ -194,7 +195,7 @@ SMCError TextParsers::ParseSMCStream(const char *stream,
result = ParseStream_SMC(&rs, RawStreamReader, smc_listener, states); result = ParseStream_SMC(&rs, RawStreamReader, smc_listener, states);
const char *errstr = GetSMCErrorString(result); const char *errstr = GetSMCErrorString(result);
smcore.Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); ke::SafeSprintf(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
return result; return result;
} }

View File

@ -40,6 +40,7 @@
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include "PhraseCollection.h" #include "PhraseCollection.h"
#include "stringutil.h" #include "stringutil.h"
#include <am-string.h>
Translator g_Translator; Translator g_Translator;
IPhraseCollection *g_pCorePhrases = NULL; IPhraseCollection *g_pCorePhrases = NULL;
@ -711,7 +712,7 @@ ConfigResult Translator::OnSourceModConfigChanged(const char *key,
unsigned int index; unsigned int index;
if (!GetLanguageByCode(value, &index)) if (!GetLanguageByCode(value, &index))
{ {
smcore.Format(error, maxlength, "Language code \"%s\" is not registered", value); ke::SafeSprintf(error, maxlength, "Language code \"%s\" is not registered", value);
return ConfigResult_Reject; return ConfigResult_Reject;
} }
@ -923,7 +924,7 @@ bool Translator::AddLanguage(const char *langcode, const char *description)
Language *pLanguage = new Language; Language *pLanguage = new Language;
idx = m_Languages.size(); idx = m_Languages.size();
smcore.Format(pLanguage->m_code2, sizeof(pLanguage->m_code2), "%s", langcode); ke::SafeSprintf(pLanguage->m_code2, sizeof(pLanguage->m_code2), "%s", langcode);
pLanguage->m_CanonicalName = m_pStringTab->AddString(lower); pLanguage->m_CanonicalName = m_pStringTab->AddString(lower);
m_LCodeLookup.insert(langcode, idx); m_LCodeLookup.insert(langcode, idx);

View File

@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 30) #define SM_LOGIC_MAGIC (0x0F47C0DE - 31)
#if defined SM_LOGIC #if defined SM_LOGIC
class IVEngineServer class IVEngineServer
@ -299,8 +299,6 @@ struct sm_core_t
void (*ConPrint)(const char *message); void (*ConPrint)(const char *message);
const char * (*GetCvarString)(ConVar*); const char * (*GetCvarString)(ConVar*);
bool (*GetCvarBool)(ConVar*); bool (*GetCvarBool)(ConVar*);
size_t (*Format)(char*, size_t, const char*, ...);
size_t (*FormatArgs)(char*, size_t, const char*,va_list ap);
bool (*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **, bool (*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **,
unsigned int, unsigned int &, size_t *, const char **); unsigned int, unsigned int &, size_t *, const char **);
size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *); size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);

View File

@ -35,6 +35,7 @@
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include <IForwardSys.h> #include <IForwardSys.h>
#include "stringutil.h" #include "stringutil.h"
#include <am-string.h>
#define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */ #define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */
#define BANFLAG_IP (1<<1) /**< Always ban by IP address */ #define BANFLAG_IP (1<<1) /**< Always ban by IP address */
@ -140,7 +141,7 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
char command[256]; char command[256];
if (ban_by_ip) if (ban_by_ip)
{ {
smcore.Format( ke::SafeSprintf(
command, command,
sizeof(command), sizeof(command),
"addip %d %s\n", "addip %d %s\n",
@ -155,7 +156,7 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
} }
else if (!gamehelpers->IsLANServer()) else if (!gamehelpers->IsLANServer())
{ {
smcore.Format( ke::SafeSprintf(
command, command,
sizeof(command), sizeof(command),
"banid %d %s\n", "banid %d %s\n",
@ -213,7 +214,7 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
{ {
if (!handled) if (!handled)
{ {
smcore.Format( ke::SafeSprintf(
command, command,
sizeof(command), sizeof(command),
"removeip %s\n", "removeip %s\n",
@ -226,7 +227,7 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
{ {
if (!handled) if (!handled)
{ {
smcore.Format( ke::SafeSprintf(
command, command,
sizeof(command), sizeof(command),
"removeid %s\n", "removeid %s\n",
@ -344,7 +345,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
/* Tell the server to ban the ip */ /* Tell the server to ban the ip */
char command[256]; char command[256];
smcore.Format( ke::SafeSprintf(
command, command,
sizeof(command), sizeof(command),
"addip %d %s\n", "addip %d %s\n",
@ -368,7 +369,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
{ {
/* Tell the server to ban the auth string */ /* Tell the server to ban the auth string */
char command[256]; char command[256];
smcore.Format( ke::SafeSprintf(
command, command,
sizeof(command), sizeof(command),
"banid %d %s\n", "banid %d %s\n",

View File

@ -34,6 +34,7 @@
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include <IPluginSys.h> #include <IPluginSys.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <am-string.h>
static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params) static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
{ {
@ -42,7 +43,7 @@ static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
IPlugin *pl = pluginsys->FindPluginByContext(pCtx->GetContext()); IPlugin *pl = pluginsys->FindPluginByContext(pCtx->GetContext());
pCtx->LocalToString(params[1], &filename); pCtx->LocalToString(params[1], &filename);
smcore.Format(buffer, sizeof(buffer), "%s", filename); ke::SafeSprintf(buffer, sizeof(buffer), "%s", filename);
/* Make sure there is no extension */ /* Make sure there is no extension */
if ((ext = strstr(buffer, ".txt")) != NULL if ((ext = strstr(buffer, ".txt")) != NULL

View File

@ -35,6 +35,7 @@
#include <ITextParsers.h> #include <ITextParsers.h>
#include <ctype.h> #include <ctype.h>
#include "stringutil.h" #include "stringutil.h"
#include <am-string.h>
inline const char *_strstr(const char *str, const char *substr) inline const char *_strstr(const char *str, const char *substr)
{ {
@ -141,7 +142,7 @@ static cell_t sm_numtostr(IPluginContext *pCtx, const cell_t *params)
{ {
char *str; char *str;
pCtx->LocalToString(params[2], &str); pCtx->LocalToString(params[2], &str);
size_t res = smcore.Format(str, params[3], "%d", params[1]); size_t res = ke::SafeSprintf(str, params[3], "%d", params[1]);
return static_cast<cell_t>(res); return static_cast<cell_t>(res);
} }
@ -174,7 +175,7 @@ static cell_t sm_floattostr(IPluginContext *pCtx, const cell_t *params)
{ {
char *str; char *str;
pCtx->LocalToString(params[2], &str); pCtx->LocalToString(params[2], &str);
size_t res = smcore.Format(str, params[3], "%f", sp_ctof(params[1])); size_t res = ke::SafeSprintf(str, params[3], "%f", sp_ctof(params[1]));
return static_cast<cell_t>(res); return static_cast<cell_t>(res);
} }

View File

@ -589,8 +589,6 @@ static sm_core_t core_bridge =
conprint, conprint,
get_cvar_string, get_cvar_string,
get_cvar_bool, get_cvar_bool,
UTIL_Format,
UTIL_FormatArgs,
gnprintf, gnprintf,
atcprintf, atcprintf,
get_game_name, get_game_name,

View File

@ -1,5 +1,5 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 sw=4 tw=99 noet :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
@ -1299,33 +1299,14 @@ size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
size_t len = vsnprintf(buffer, maxlength, fmt, ap); size_t len = ke::SafeVsprintf(buffer, maxlength, fmt, ap);
va_end(ap); va_end(ap);
if (len >= maxlength)
{
buffer[maxlength - 1] = '\0';
return (maxlength - 1);
}
else
{
return len; return len;
}
} }
size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap) size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap)
{ {
size_t len = vsnprintf(buffer, maxlength, fmt, ap); return ke::SafeVsprintf(buffer, maxlength, fmt, ap);
if (len >= maxlength)
{
buffer[maxlength - 1] = '\0';
return (maxlength - 1);
}
else
{
return len;
}
} }
char *sm_strdup(const char *str) char *sm_strdup(const char *str)