Skip to content

Commit 5611ec5

Browse files
HeadlineKyleSanderson
authored andcommitted
Migrate extensions to common AMTL string funcs (#785)
1 parent 6c7e29c commit 5611ec5

File tree

19 files changed

+53
-44
lines changed

19 files changed

+53
-44
lines changed

core/PlayerManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,18 +2050,18 @@ void CPlayer::UpdateAuthIds()
20502050
}
20512051

20522052
char szAuthBuffer[64];
2053-
snprintf(szAuthBuffer, sizeof(szAuthBuffer), "STEAM_%u:%u:%u", steam2universe, m_SteamId.GetAccountID() & 1, m_SteamId.GetAccountID() >> 1);
2053+
ke::SafeSprintf(szAuthBuffer, sizeof(szAuthBuffer), "STEAM_%u:%u:%u", steam2universe, m_SteamId.GetAccountID() & 1, m_SteamId.GetAccountID() >> 1);
20542054

20552055
m_Steam2Id = szAuthBuffer;
20562056

20572057
// TODO: make sure all hl2sdks' steamclientpublic.h have k_unSteamUserDesktopInstance.
20582058
if (m_SteamId.GetUnAccountInstance() == 1 /* k_unSteamUserDesktopInstance */)
20592059
{
2060-
snprintf(szAuthBuffer, sizeof(szAuthBuffer), "[U:%u:%u]", m_SteamId.GetEUniverse(), m_SteamId.GetAccountID());
2060+
ke::SafeSprintf(szAuthBuffer, sizeof(szAuthBuffer), "[U:%u:%u]", m_SteamId.GetEUniverse(), m_SteamId.GetAccountID());
20612061
}
20622062
else
20632063
{
2064-
snprintf(szAuthBuffer, sizeof(szAuthBuffer), "[U:%u:%u:%u]", m_SteamId.GetEUniverse(), m_SteamId.GetAccountID(), m_SteamId.GetUnAccountInstance());
2064+
ke::SafeSprintf(szAuthBuffer, sizeof(szAuthBuffer), "[U:%u:%u:%u]", m_SteamId.GetEUniverse(), m_SteamId.GetAccountID(), m_SteamId.GetUnAccountInstance());
20652065
}
20662066

20672067
m_Steam3Id = szAuthBuffer;

core/logic/AdminCache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,14 @@ bool AdminCache::GetUnifiedSteamIdentity(const char *ident, char *out, size_t ma
10901090
else if (len >= 11 && !strncmp(ident, "STEAM_", 6) && ident[8] != '_')
10911091
{
10921092
// non-bot/lan Steam2 Id, strip off the STEAM_* part
1093-
snprintf(out, maxlen, "%s", &ident[8]);
1093+
ke::SafeStrcpy(out, maxlen, &ident[8]);
10941094
return true;
10951095
}
10961096
else if (len >= 7 && !strncmp(ident, "[U:", 3) && ident[len-1] == ']')
10971097
{
10981098
// Steam3 Id, replicate the Steam2 Post-"STEAM_" part
10991099
uint32_t accountId = strtoul(&ident[5], nullptr, 10);
1100-
snprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
1100+
ke::SafeSprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
11011101
return true;
11021102
}
11031103
else
@@ -1124,7 +1124,7 @@ bool AdminCache::GetUnifiedSteamIdentity(const char *ident, char *out, size_t ma
11241124
&& accountType == k_EAccountTypeIndividual && accountInstance <= k_unSteamUserWebInstance
11251125
)
11261126
{
1127-
snprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
1127+
ke::SafeSprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
11281128
return true;
11291129
}
11301130
}

core/logic/ExtensionSys.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ bool CLocalExtension::Load(char *error, size_t maxlength)
176176
{
177177
m_pLib->CloseLibrary();
178178
m_pLib = NULL;
179-
snprintf(error, maxlength, "Unable to find extension entry point");
179+
ke::SafeStrcpy(error, maxlength, "Unable to find extension entry point");
180180
return false;
181181
}
182182

@@ -246,7 +246,7 @@ void CLocalExtension::Unload()
246246

247247
bool CRemoteExtension::Reload(char *error, size_t maxlength)
248248
{
249-
snprintf(error, maxlength, "Remote extensions do not support reloading");
249+
ke::SafeStrcpy(error, maxlength, "Remote extensions do not support reloading");
250250
return false;
251251
}
252252

@@ -280,13 +280,13 @@ bool CExtension::PerformAPICheck(char *error, size_t maxlength)
280280
{
281281
if (!m_pAPI)
282282
{
283-
snprintf(error, maxlength, "No IExtensionInterface instance provided");
283+
ke::SafeStrcpy(error, maxlength, "No IExtensionInterface instance provided");
284284
return false;
285285
}
286286

287287
if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
288288
{
289-
snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
289+
ke::SafeSprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
290290
return false;
291291
}
292292

@@ -493,7 +493,7 @@ bool CExtension::IsRunning(char *error, size_t maxlength)
493493
{
494494
if (error)
495495
{
496-
snprintf(error, maxlength, "%s", m_Error.c_str());
496+
ke::SafeStrcpy(error, maxlength, m_Error.c_str());
497497
}
498498
return false;
499499
}
@@ -1136,7 +1136,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
11361136
if (pExt->unload_code == (unsigned)atoi(unload))
11371137
{
11381138
char filename[PLATFORM_MAX_PATH];
1139-
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1139+
ke::SafeStrcpy(filename, PLATFORM_MAX_PATH, pExt->GetFilename());
11401140
UnloadExtension(pExt);
11411141
rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
11421142
}
@@ -1151,7 +1151,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
11511151
|| (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
11521152
{
11531153
char filename[PLATFORM_MAX_PATH];
1154-
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1154+
ke::SafeStrcpy(filename, PLATFORM_MAX_PATH, pExt->GetFilename());
11551155
UnloadExtension(pExt);
11561156
rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
11571157
return;
@@ -1252,7 +1252,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
12521252
char filename[PLATFORM_MAX_PATH];
12531253
char error[255];
12541254

1255-
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1255+
ke::SafeStrcpy(filename, PLATFORM_MAX_PATH, pExt->GetFilename());
12561256

12571257
if (pExt->Reload(error, sizeof(error)))
12581258
{

core/logic/LibrarySys.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ CDirectory::CDirectory(const char *path)
6666
{
6767
#if defined PLATFORM_WINDOWS
6868
char newpath[PLATFORM_MAX_PATH];
69-
snprintf(newpath, sizeof(newpath), "%s\\*.*", path);
69+
ke::SafeSprintf(newpath, sizeof(newpath), "%s\\*.*", path);
7070
m_dir = FindFirstFileA(newpath, &m_fd);
7171
if (!IsValid())
7272
{
@@ -78,7 +78,7 @@ CDirectory::CDirectory(const char *path)
7878
{
7979
/* :TODO: we need to read past "." and ".."! */
8080
ep = readdir(m_dir);
81-
snprintf(m_origpath, PLATFORM_MAX_PATH, "%s", path);
81+
ke::SafeStrcpy(m_origpath, PLATFORM_MAX_PATH, path);
8282
} else {
8383
ep = NULL;
8484
}
@@ -125,7 +125,7 @@ bool CDirectory::IsEntryDirectory()
125125
return ((m_fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
126126
#elif defined PLATFORM_POSIX
127127
char temppath[PLATFORM_MAX_PATH];
128-
int ret = snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
128+
int ret = ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
129129
if (static_cast<size_t>(ret) >= sizeof(temppath))
130130
return false;
131131
return ke::file::IsDirectory(temppath);
@@ -138,7 +138,7 @@ bool CDirectory::IsEntryFile()
138138
return !(m_fd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE));
139139
#elif defined PLATFORM_POSIX
140140
char temppath[PLATFORM_MAX_PATH];
141-
int ret = snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
141+
int ret = ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
142142
if (static_cast<size_t>(ret) >= sizeof(temppath))
143143
return false;
144144
return ke::file::IsFile(temppath);

core/logic/RootConsoleMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
166166
{
167167
buffer[len++] = ' ';
168168
}
169-
len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
169+
len += ke::SafeSprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
170170
ConsolePrint("%s", buffer);
171171
}
172172
}

core/logic/smn_filesystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
321321
{
322322
size_t len = strlen(path);
323323
char wildcardedPath[PLATFORM_MAX_PATH];
324-
snprintf(wildcardedPath, sizeof(wildcardedPath), "%s%s*", path, (path[len-1] != '/' && path[len-1] != '\\') ? "/" : "");
324+
ke::SafeSprintf(wildcardedPath, sizeof(wildcardedPath), "%s%s*", path, (path[len-1] != '/' && path[len-1] != '\\') ? "/" : "");
325325

326326
char *pathID;
327327
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)

core/logic/smn_players.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authTyp
397397
}
398398

399399
char szAuth[64];
400-
snprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId);
400+
ke::SafeSprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId);
401401

402402
pCtx->StringToLocal(local_addr, bytes, szAuth);
403403
}

core/sourcemm_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen
110110
{
111111
if (error)
112112
{
113-
snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
113+
ke::SafeSprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
114114
}
115115
return false;
116116
}

extensions/clientprefs/extension.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late)
6666

6767
if (DBInfo == NULL)
6868
{
69-
snprintf(error, maxlength, "Could not find any suitable database configs");
69+
ke::SafeStrcpy(error, maxlength, "Could not find any suitable database configs");
7070
return false;
7171
}
7272

@@ -81,7 +81,7 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late)
8181

8282
if (Driver == NULL)
8383
{
84-
snprintf(error, maxlength, "Could not load DB Driver \"%s\"", DBInfo->driver);
84+
ke::SafeSprintf(error, maxlength, "Could not load DB Driver \"%s\"", DBInfo->driver);
8585
return false;
8686
}
8787

extensions/cstrike/extension.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late)
6363
#if SOURCE_ENGINE != SE_CSGO
6464
if (strcmp(g_pSM->GetGameFolderName(), "cstrike") != 0)
6565
{
66-
snprintf(error, maxlength, "Cannot Load Cstrike Extension on mods other than CS:S and CS:GO");
66+
ke::SafeStrcpy(error, maxlength, "Cannot Load Cstrike Extension on mods other than CS:S and CS:GO");
6767
return false;
6868
}
6969
#endif
@@ -76,7 +76,7 @@ bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late)
7676
{
7777
if (error)
7878
{
79-
snprintf(error, maxlength, "Could not read sm-cstrike.games: %s", conf_error);
79+
ke::SafeSprintf(error, maxlength, "Could not read sm-cstrike.games: %s", conf_error);
8080
}
8181
return false;
8282
}

0 commit comments

Comments
 (0)