diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index ab202b20..350b6350 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. @@ -37,6 +37,7 @@ #include "HalfLife2.h" #include "logic_bridge.h" #include "sourcemod.h" +#include #if SOURCE_ENGINE == SE_DOTA SH_DECL_EXTERN2_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommandContext &, const CCommand &); @@ -433,7 +434,7 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args) */ char new_buf[80]; strcpy(new_buf, "sm_"); - strncopy(&new_buf[3], cmd_buf, sizeof(new_buf)-3); + ke::SafeStrcpy(&new_buf[3], sizeof(new_buf)-3, cmd_buf); /* Recheck */ if (!g_ConCmds.LookForSourceModCommand(new_buf)) @@ -454,10 +455,10 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args) { len = UTIL_Format(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args); } else { - len = strncopy(m_ToExecute, args, sizeof(m_ToExecute)); + len = ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args); } } else { - strncopy(m_ToExecute, args, sizeof(m_ToExecute)); + ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args); } return true; diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index bc04ad92..ecd29e9a 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -434,7 +434,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) char *dptr = descr; /* Print comments until there is no more */ - strncopy(descr, cvar->GetHelpText(), sizeof(descr)); + ke::SafeStrcpy(descr, sizeof(descr), cvar->GetHelpText()); while (*dptr != '\0') { /* Find the next line */ diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 4a8d9822..f66e22e5 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -831,7 +831,7 @@ void CHalfLife2::PushCommandStack(const CCommand *cmd) info.args = cmd; #if SOURCE_ENGINE <= SE_DARKMESSIAH - strncopy(info.cmd, cmd->Arg(0), sizeof(info.cmd)); + ke::SafeStrcpy(info.cmd, sizeof(info.cmd), cmd->Arg(0)); #endif m_CommandStack.push(info); @@ -1247,7 +1247,7 @@ SMFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) } else { - strncopy(pMapName, &results[0][helperCmdLen + 1], nMapNameMax); + ke::SafeStrcpy(pMapName, nMapNameMax, &results[0][helperCmdLen + 1]); return SMFindMapResult::FuzzyMatch; } #elif SOURCE_ENGINE == SE_TF2 @@ -1263,7 +1263,7 @@ bool CHalfLife2::IsMapValid(const char *map) return false; static char szTmp[PLATFORM_MAX_PATH]; - strncopy(szTmp, map, sizeof(szTmp)); + ke::SafeStrcpy(szTmp, sizeof(szTmp), map); return FindMap(szTmp, sizeof(szTmp)) != SMFindMapResult::NotFound; } diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index 24b261a1..1072511e 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. @@ -382,7 +382,7 @@ bool CValveMenu::SetExtOption(MenuOption option, const void *valuePtr) { if (option == MenuOption_IntroMessage) { - strncopy(m_IntroMsg, (const char *)valuePtr, sizeof(m_IntroMsg)); + ke::SafeStrcpy(m_IntroMsg, sizeof(m_IntroMsg), (const char *)valuePtr); return true; } else if (option == MenuOption_IntroColor) { unsigned int *array = (unsigned int *)valuePtr; diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 58596dcd..55448251 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -1657,7 +1657,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) { info->targets[0] = client; info->num_targets = 1; - strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, pTarget->GetName()); info->target_name_style = COMMAND_TARGETNAME_RAW; } else @@ -1731,7 +1731,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) { info->targets[0] = i; info->num_targets = 1; - strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, pTarget->GetName()); info->target_name_style = COMMAND_TARGETNAME_RAW; } else @@ -1761,7 +1761,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) { info->targets[0] = i; info->num_targets = 1; - strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, pTarget->GetName()); info->target_name_style = COMMAND_TARGETNAME_RAW; } else @@ -1780,7 +1780,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) { info->targets[0] = info->admin; info->num_targets = 1; - strncopy(info->target_name, pAdmin->GetName(), info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, pAdmin->GetName()); info->target_name_style = COMMAND_TARGETNAME_RAW; } else @@ -1799,7 +1799,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) if (strcmp(info->pattern, "@all") == 0) { is_multi = true; - strncopy(info->target_name, "all players", info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, "all players"); info->target_name_style = COMMAND_TARGETNAME_ML; } else if (strcmp(info->pattern, "@dead") == 0) @@ -1812,7 +1812,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) return; } info->flags |= COMMAND_FILTER_DEAD; - strncopy(info->target_name, "all dead players", info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, "all dead players"); info->target_name_style = COMMAND_TARGETNAME_ML; } else if (strcmp(info->pattern, "@alive") == 0) @@ -1824,7 +1824,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) info->reason = COMMAND_TARGET_NOT_DEAD; return; } - strncopy(info->target_name, "all alive players", info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, "all alive players"); info->target_name_style = COMMAND_TARGETNAME_ML; info->flags |= COMMAND_FILTER_ALIVE; } @@ -1837,21 +1837,21 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) info->reason = COMMAND_TARGET_NOT_HUMAN; return; } - strncopy(info->target_name, "all bots", info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, "all bots"); info->target_name_style = COMMAND_TARGETNAME_ML; bots_only = true; } else if (strcmp(info->pattern, "@humans") == 0) { is_multi = true; - strncopy(info->target_name, "all humans", info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, "all humans"); info->target_name_style = COMMAND_TARGETNAME_ML; info->flags |= COMMAND_FILTER_NO_BOTS; } else if (strcmp(info->pattern, "@!me") == 0) { is_multi = true; - strncopy(info->target_name, "all players", info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, "all players"); info->target_name_style = COMMAND_TARGETNAME_ML; skip_client = info->admin; } @@ -1923,7 +1923,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) { info->targets[0] = found_client; info->num_targets = 1; - strncopy(info->target_name, pFoundClient->GetName(), info->target_name_maxlength); + ke::SafeStrcpy(info->target_name, info->target_name_maxlength, pFoundClient->GetName()); info->target_name_style = COMMAND_TARGETNAME_RAW; } else @@ -2071,7 +2071,7 @@ void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity) m_Serial.bits.serial = g_PlayerSerialCount++; char ip2[24], *ptr; - strncopy(ip2, ip, sizeof(ip2)); + ke::SafeStrcpy(ip2, sizeof(ip2), ip); if ((ptr = strchr(ip2, ':')) != NULL) { *ptr = '\0'; diff --git a/core/UserMessagePBHelpers.h b/core/UserMessagePBHelpers.h index d0fc2b31..fba9d656 100644 --- a/core/UserMessagePBHelpers.h +++ b/core/UserMessagePBHelpers.h @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod * Copyright (C) 2013 AlliedModders LLC. All rights reserved. @@ -34,6 +34,7 @@ #include #include +#include #define GETCHECK_FIELD() \ const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \ @@ -672,7 +673,7 @@ public: CHECK_FIELD_NOT_REPEATED(); std::string scratch; - strncopy(out, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str(), size); + ke::SafeStrcpy(out, size, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str()); return true; } @@ -695,7 +696,7 @@ public: CHECK_REPEATED_ELEMENT(index); std::string scratch; - strncopy(out, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str(), size); + ke::SafeStrcpy(out, size, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str()); return true; } diff --git a/core/UserMessages.cpp b/core/UserMessages.cpp index a4f7c301..7aadd9e9 100644 --- a/core/UserMessages.cpp +++ b/core/UserMessages.cpp @@ -38,6 +38,7 @@ #elif SOURCE_ENGINE == SE_CSGO #include #endif +#include UserMessages g_UserMsgs; @@ -158,7 +159,7 @@ bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) con if (!pszName) return false; - strncopy(buffer, pszName, maxlength); + ke::SafeStrcpy(buffer, maxlength, pszName); return true; #else if (m_FallbackSearch) @@ -171,7 +172,7 @@ bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) con if (msg) { - strncopy(buffer, msg, maxlength); + ke::SafeStrcpy(buffer, maxlength, msg); return true; } diff --git a/core/concmd_cleaner.cpp b/core/concmd_cleaner.cpp index 2f2d2c04..009608b5 100644 --- a/core/concmd_cleaner.cpp +++ b/core/concmd_cleaner.cpp @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. @@ -36,6 +36,7 @@ #include "sm_stringutil.h" #include "sourcemm_api.h" #include "compat_wrappers.h" +#include #if SOURCE_ENGINE >= SE_ORANGEBOX SH_DECL_HOOK1_void(ICvar, UnregisterConCommand, SH_NOATTRIB, 0, ConCommandBase *); @@ -146,7 +147,7 @@ public: info->pBase = pBase; info->cls = cls; - strncopy(info->name, pBase->GetName(), sizeof(info->name)); + ke::SafeStrcpy(info->name, sizeof(info->name), pBase->GetName()); tracked_bases.push_back(info); } diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 64acc40c..08b357a5 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -469,7 +469,7 @@ bool CoreProviderImpl::GetGameName(char *buffer, size_t maxlength) const char *str; if ((str = pGameInfo->GetString("game", NULL)) != NULL) { - strncopy(buffer, str, maxlength); + ke::SafeStrcpy(buffer, maxlength, str); pGameInfo->deleteThis(); return true; } diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index ad214677..ddc8eea4 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -41,11 +41,6 @@ #include #include -unsigned int strncopy(char *dest, const char *src, size_t count) -{ - return ke::SafeStrcpy(dest, count, src); -} - size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...) { va_list ap; diff --git a/core/sm_stringutil.h b/core/sm_stringutil.h index f5e786c7..3ea0e560 100644 --- a/core/sm_stringutil.h +++ b/core/sm_stringutil.h @@ -42,7 +42,6 @@ using namespace SourceMod; #define IS_STR_FILLED(var) (var[0] != '\0') -unsigned int strncopy(char *dest, const char *src, size_t count); 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); diff --git a/core/smn_entities.cpp b/core/smn_entities.cpp index 4917f503..5abcf8d3 100644 --- a/core/smn_entities.cpp +++ b/core/smn_entities.cpp @@ -1003,7 +1003,7 @@ static cell_t SetEntDataString(IPluginContext *pContext, const cell_t *params) char *dest = (char *)((uint8_t *)pEntity + offset); pContext->LocalToString(params[3], &src); - size_t len = strncopy(dest, src, params[4]); + size_t len = ke::SafeStrcpy(dest, params[4], src); if (params[5] && (pEdict != NULL)) { @@ -2165,7 +2165,7 @@ static cell_t SetEntPropString(IPluginContext *pContext, const cell_t *params) else { char *dest = (char *) ((uint8_t *) pEntity + offset); - len = strncopy(dest, src, maxlen); + len = ke::SafeStrcpy(dest, maxlen, src); } if (params[2] == Prop_Send && (pEdict != NULL)) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 6139a735..6b1f6a70 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -152,7 +152,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late { if (gamepath[i] == PLATFORM_SEP_CHAR) { - strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir)); + ke::SafeStrcpy(m_ModDir, sizeof(m_ModDir), &gamepath[++i]); break; } }