Address C4267 compiler warnings (#647)

Implicit conversion from `size_t` to a smaller type
This commit is contained in:
Jack 2024-01-21 19:34:19 +00:00 committed by GitHub
parent e72f0cbbac
commit 7f84bdf8fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 57 additions and 57 deletions

View File

@ -445,7 +445,7 @@ bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLeng
else
{
data = dat->second.get();
dataLength = dat->first;
dataLength = (unsigned int)dat->first;
}
}

View File

@ -15,15 +15,15 @@ void InitialiseNorthstarPrefix()
std::string cla = std::string(clachar);
if (strncmp(cla.substr(9, 1).c_str(), "\"", 1))
{
int space = cla.find(" ");
size_t space = cla.find(" ");
std::string dirname = cla.substr(9, space - 9);
NORTHSTAR_FOLDER_PREFIX = dirname;
}
else
{
std::string quote = "\"";
int quote1 = cla.find(quote);
int quote2 = (cla.substr(quote1 + 1)).find(quote);
size_t quote1 = cla.find(quote);
size_t quote2 = (cla.substr(quote1 + 1)).find(quote);
std::string dirname = cla.substr(quote1 + 1, quote2);
NORTHSTAR_FOLDER_PREFIX = dirname;
}

View File

@ -382,7 +382,7 @@ void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue)
if (pszTempVal)
{
int len = strlen(pszTempVal) + 1;
size_t len = strlen(pszTempVal) + 1;
if (len > m_Value.m_iStringLength)
{

View File

@ -77,7 +77,7 @@ void __fileAutohook::Dispatch()
void __fileAutohook::DispatchForModule(const char* pModuleName)
{
const int iModuleNameLen = strlen(pModuleName);
const size_t iModuleNameLen = strlen(pModuleName);
for (__autohook* hook : hooks)
if ((hook->iAddressResolutionMode == __autohook::OFFSET_STRING && !strncmp(pModuleName, hook->pAddrString, iModuleNameLen)) ||
@ -87,14 +87,14 @@ void __fileAutohook::DispatchForModule(const char* pModuleName)
ManualHook::ManualHook(const char* funcName, LPVOID func) : pHookFunc(func), ppOrigFunc(nullptr)
{
const int iFuncNameStrlen = strlen(funcName);
const size_t iFuncNameStrlen = strlen(funcName);
pFuncName = new char[iFuncNameStrlen];
memcpy(pFuncName, funcName, iFuncNameStrlen);
}
ManualHook::ManualHook(const char* funcName, LPVOID* orig, LPVOID func) : pHookFunc(func), ppOrigFunc(orig)
{
const int iFuncNameStrlen = strlen(funcName);
const size_t iFuncNameStrlen = strlen(funcName);
pFuncName = new char[iFuncNameStrlen];
memcpy(pFuncName, funcName, iFuncNameStrlen);
}
@ -141,7 +141,7 @@ uintptr_t ParseDLLOffsetString(const char* pAddrString)
uintptr_t iOffset = 0;
int iOffsetBegin = iDllNameEnd;
int iOffsetEnd = strlen(pAddrString);
size_t iOffsetEnd = strlen(pAddrString);
// seek until we hit the start of the number offset
for (; !(pAddrString[iOffsetBegin] >= '0' && pAddrString[iOffsetBegin] <= '9') && pAddrString[iOffsetBegin]; iOffsetBegin++)

View File

@ -119,7 +119,7 @@ public:
{
iAddressResolutionMode = ABSOLUTE_ADDR;
const int iFuncNameStrlen = strlen(funcName) + 1;
const size_t iFuncNameStrlen = strlen(funcName) + 1;
pFuncName = new char[iFuncNameStrlen];
memcpy(pFuncName, funcName, iFuncNameStrlen);
@ -131,11 +131,11 @@ public:
{
iAddressResolutionMode = OFFSET_STRING;
const int iFuncNameStrlen = strlen(funcName) + 1;
const size_t iFuncNameStrlen = strlen(funcName) + 1;
pFuncName = new char[iFuncNameStrlen];
memcpy(pFuncName, funcName, iFuncNameStrlen);
const int iAddrStrlen = strlen(addrString) + 1;
const size_t iAddrStrlen = strlen(addrString) + 1;
pAddrString = new char[iAddrStrlen];
memcpy(pAddrString, addrString, iAddrStrlen);
@ -147,15 +147,15 @@ public:
{
iAddressResolutionMode = PROCADDRESS;
const int iFuncNameStrlen = strlen(funcName) + 1;
const size_t iFuncNameStrlen = strlen(funcName) + 1;
pFuncName = new char[iFuncNameStrlen];
memcpy(pFuncName, funcName, iFuncNameStrlen);
const int iModuleNameStrlen = strlen(moduleName) + 1;
const size_t iModuleNameStrlen = strlen(moduleName) + 1;
pModuleName = new char[iModuleNameStrlen];
memcpy(pModuleName, moduleName, iModuleNameStrlen);
const int iProcNameStrlen = strlen(procName) + 1;
const size_t iProcNameStrlen = strlen(procName) + 1;
pProcName = new char[iProcNameStrlen];
memcpy(pProcName, procName, iProcNameStrlen);
@ -293,7 +293,7 @@ public:
{
m_pTarget = pTarget;
const int iAddrStrlen = strlen(pAddrString) + 1;
const size_t iAddrStrlen = strlen(pAddrString) + 1;
m_pAddrString = new char[iAddrStrlen];
memcpy(m_pAddrString, pAddrString, iAddrStrlen);

View File

@ -630,7 +630,7 @@ public:
// at the head to make reading and detecting the end efficient.
int nHead = m_DataBytes & 3;
int posBytes = startPos / 8;
size_t posBytes = startPos / 8;
if ((m_DataBytes < 4) || (nHead && (posBytes < nHead)))
{
// partial first dword
@ -652,7 +652,7 @@ public:
}
else
{
int adjustedPos = startPos - (nHead << 3);
size_t adjustedPos = startPos - (nHead << 3);
m_DataIn = reinterpret_cast<u32 const*>(reinterpret_cast<u8 const*>(m_Data) + ((adjustedPos / 32) << 2) + nHead);

View File

@ -103,7 +103,7 @@ inline std::vector<uint8_t> HexBytesToString(const char* pHexString)
{
std::vector<uint8_t> ret;
int size = strlen(pHexString);
size_t size = strlen(pHexString);
for (int i = 0; i < size; i++)
{
// If this is a space character, ignore it
@ -289,7 +289,7 @@ inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const
std::vector<uint8_t> vRet;
std::string sMask;
int size = strlen(pPatternString);
size_t size = strlen(pPatternString);
for (int i = 0; i < size; i++)
{
// If this is a space character, ignore it

View File

@ -95,18 +95,18 @@ void ExternalConsoleSink::custom_sink_it_(const custom_log_msg& msg)
std::string name {msg.logger_name.begin(), msg.logger_name.end()};
std::string name_str = "[NAME]";
int name_pos = str.find(name_str);
size_t name_pos = str.find(name_str);
str.replace(name_pos, name_str.length(), msg.origin->ANSIColor + "[" + name + "]" + default_color);
std::string level_str = "[LVL]";
int level_pos = str.find(level_str);
size_t level_pos = str.find(level_str);
str.replace(level_pos, level_str.length(), levelColor + "[" + std::string(level_names[msg.level]) + "]" + default_color);
out += str;
}
// print the string to the console - this is definitely bad i think
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
auto ignored = WriteConsoleA(handle, out.c_str(), std::strlen(out.c_str()), nullptr, nullptr);
auto ignored = WriteConsoleA(handle, out.c_str(), (DWORD)std::strlen(out.c_str()), nullptr, nullptr);
(void)ignored;
}

View File

@ -635,7 +635,7 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
{
char* escapedPassword = curl_easy_escape(curl, passwordStr.c_str(), passwordStr.length());
char* escapedPassword = curl_easy_escape(curl, passwordStr.c_str(), (int)passwordStr.length());
curl_easy_setopt(
curl,
@ -924,7 +924,7 @@ void MasterServerManager::ProcessConnectionlessPacketSigreq1(std::string data)
CURL* curl = curl_easy_init();
SetCommonHttpClientOptions(curl);
char* rejectEnc = curl_easy_escape(curl, reject.c_str(), reject.length());
char* rejectEnc = curl_easy_escape(curl, reject.c_str(), (int)reject.length());
if (!rejectEnc)
{
spdlog::error("failed to handle Atlas connect request {}: failed to escape reject", token);

View File

@ -23,18 +23,18 @@ ModDownloader::ModDownloader()
if (clachar)
{
std::string url;
int iFlagStringLength = strlen(CUSTOM_MODS_URL_FLAG);
size_t iFlagStringLength = strlen(CUSTOM_MODS_URL_FLAG);
std::string cla = std::string(clachar);
if (strncmp(cla.substr(iFlagStringLength, 1).c_str(), "\"", 1))
{
int space = cla.find(" ");
size_t space = cla.find(" ");
url = cla.substr(iFlagStringLength, space - iFlagStringLength);
}
else
{
std::string quote = "\"";
int quote1 = cla.find(quote);
int quote2 = (cla.substr(quote1 + 1)).find(quote);
size_t quote1 = cla.find(quote);
size_t quote2 = (cla.substr(quote1 + 1)).find(quote);
url = cla.substr(quote1 + 1, quote2);
}
spdlog::info("Found custom verified mods URL in command line argument: {}", url);

View File

@ -188,7 +188,7 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs*
plugin.run_frame = (PLUGIN_RUNFRAME)GetProcAddress(pluginLib, "PLUGIN_RUNFRAME");
plugin.handle = m_vLoadedPlugins.size();
plugin.handle = (int)m_vLoadedPlugins.size();
plugin.logger = std::make_shared<ColoredLogger>(plugin.displayName.c_str(), NS::Colors::PLUGIN);
RegisterLogger(plugin.logger);
NS::log::PLUGINSYS->info("Loading plugin {} version {}", plugin.displayName, plugin.version);

View File

@ -281,7 +281,7 @@ bool LoadNorthstar()
std::string cla = std::string(clachar);
if (strncmp(cla.substr(9, 1).c_str(), "\"", 1))
{
int space = cla.find(" ");
size_t space = cla.find(" ");
std::string dirname = cla.substr(9, space - 9);
std::cout << "[*] Found profile in command line arguments: " << dirname << std::endl;
strProfile = dirname.c_str();
@ -289,8 +289,8 @@ bool LoadNorthstar()
else
{
std::string quote = "\"";
int quote1 = cla.find(quote);
int quote2 = (cla.substr(quote1 + 1)).find(quote);
size_t quote1 = cla.find(quote);
size_t quote2 = (cla.substr(quote1 + 1)).find(quote);
std::string dirname = cla.substr(quote1 + 1, quote2);
std::cout << "[*] Found profile in command line arguments: " << dirname << std::endl;
strProfile = dirname;

View File

@ -26,7 +26,7 @@ ADD_SQFUNC("bool", NSMasterServerConnectionSuccessful, "", "", ScriptContext::UI
ADD_SQFUNC("int", NSGetServerCount, "", "", ScriptContext::UI)
{
g_pSquirrel<context>->pushinteger(sqvm, g_pMasterServerManager->m_vRemoteServers.size());
g_pSquirrel<context>->pushinteger(sqvm, (SQInteger)g_pMasterServerManager->m_vRemoteServers.size());
return SQRESULT_NOTNULL;
}
@ -146,7 +146,7 @@ ADD_SQFUNC("array<ServerInfo>", NSGetGameServers, "", "", ScriptContext::UI)
g_pSquirrel<context>->pushnewstructinstance(sqvm, 11);
// index
g_pSquirrel<context>->pushinteger(sqvm, i);
g_pSquirrel<context>->pushinteger(sqvm, (SQInteger)i);
g_pSquirrel<context>->sealstructslot(sqvm, 0);
// id

View File

@ -308,7 +308,7 @@ REPLACE_SQFUNC(GetDataTableRowCount, (ScriptContext::UI | ScriptContext::CLIENT
return g_pSquirrel<context>->m_funcOriginals["GetDatatableRowCount"](sqvm);
CSVData* csv = *pData;
g_pSquirrel<context>->pushinteger(sqvm, csv->dataPointers.size());
g_pSquirrel<context>->pushinteger(sqvm, (SQInteger)csv->dataPointers.size());
return SQRESULT_NOTNULL;
}

View File

@ -320,11 +320,11 @@ template <ScriptContext context> int HttpRequestHandler::MakeHttpRequest(const H
bool isFirstValue = true;
for (const auto& kv : requestParameters.queryParameters)
{
char* key = curl_easy_escape(curl, kv.first.c_str(), kv.first.length());
char* key = curl_easy_escape(curl, kv.first.c_str(), (int)kv.first.length());
for (const std::string& queryValue : kv.second)
{
char* value = curl_easy_escape(curl, queryValue.c_str(), queryValue.length());
char* value = curl_easy_escape(curl, queryValue.c_str(), (int)queryValue.length());
if (isFirstValue && !bUrlContainsQuery)
{

View File

@ -222,8 +222,8 @@ int ConCommand_banCompletion(const char* const partial, char commands[COMMAND_CO
const char* cmdName = partial;
const char* query = partial + (space == nullptr ? 0 : space - partial) + 1;
const int queryLength = strlen(query);
const int cmdLength = strlen(cmdName) - queryLength;
const size_t queryLength = strlen(query);
const size_t cmdLength = strlen(cmdName) - queryLength;
int numCompletions = 0;
for (int i = 0; i < GetMaxPlayers() && numCompletions < COMMAND_COMPLETION_MAXITEMS - 2; i++)

View File

@ -291,7 +291,7 @@ void,, (CBaseClient* self))
{
g_pServerAuthentication->m_bForceResetLocalPlayerPersistence = false;
g_pServerAuthentication->WritePersistentData(self);
g_pServerPresence->SetPlayerCount(g_pServerAuthentication->m_PlayerAuthenticationData.size());
g_pServerPresence->SetPlayerCount((int)g_pServerAuthentication->m_PlayerAuthenticationData.size());
}
CBaseClient__ActivatePlayer(self);
@ -326,7 +326,7 @@ void,, (CBaseClient* self, uint32_t unknownButAlways1, const char* pReason, ...)
g_pServerLimits->RemovePlayer(self);
}
g_pServerPresence->SetPlayerCount(g_pServerAuthentication->m_PlayerAuthenticationData.size());
g_pServerPresence->SetPlayerCount((int)g_pServerAuthentication->m_PlayerAuthenticationData.size());
_CBaseClient__Disconnect(self, unknownButAlways1, buf);
}

View File

@ -262,7 +262,7 @@ bool, __fastcall, (const char* pModName)) // 48 83 EC 28 48 8B 0D ? ? ? ? 48 8D
// clang-format on
{
// somewhat temp, store the modname here, since we don't have a proper ptr in engine to it rn
int iSize = strlen(pModName);
size_t iSize = strlen(pModName);
g_pModName = new char[iSize + 1];
strcpy(g_pModName, pModName);
@ -323,7 +323,7 @@ bool, __fastcall, (CBaseClient* self, uint32_t unknown, const char* pCommandStri
"load_recent_checkpoint" // This is the instant-respawn exploit, literally just calls RespawnPlayer()
};
int iCmdLength = strlen(tempCommand.Arg(0));
size_t iCmdLength = strlen(tempCommand.Arg(0));
bool bIsBadCommand = false;
for (auto& blockedCommand : blockedCommands)

View File

@ -60,7 +60,7 @@ void ConCommand_cvar_setdefaultvalue(const CCommand& arg)
}
// unfortunately no way for us to not leak memory here, as default value might not be in writeable memory by default
int nLen = strlen(arg.Arg(2));
size_t nLen = strlen(arg.Arg(2));
char* pBuf = new char[nLen + 1];
strncpy_s(pBuf, nLen + 1, arg.Arg(2), nLen);
@ -83,7 +83,7 @@ void ConCommand_cvar_setvalueanddefaultvalue(const CCommand& arg)
}
// unfortunately no way for us to not leak memory here, as default value might not be in writeable memory by default
int nLen = strlen(arg.Arg(2));
size_t nLen = strlen(arg.Arg(2));
char* pBuf = new char[nLen + 1];
strncpy_s(pBuf, nLen + 1, arg.Arg(2), nLen);

View File

@ -659,7 +659,7 @@ template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBu
pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object
pushroottable(m_pSQVM->sqvm);
int argsAmount = message.args.size();
size_t argsAmount = message.args.size();
if (message.isExternal && message.externalFunc != NULL)
{
@ -674,7 +674,7 @@ template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBu
}
}
_call(m_pSQVM->sqvm, argsAmount);
_call(m_pSQVM->sqvm, (SQInteger)argsAmount);
}
}

View File

@ -399,7 +399,7 @@ public:
v();
}
return _call(m_pSQVM->sqvm, functionVector.size());
return _call(m_pSQVM->sqvm, (SQInteger)functionVector.size());
}
#pragma endregion
@ -470,7 +470,7 @@ template <ScriptContext context, typename T>
requires (std::convertible_to<T, std::string> || std::is_constructible_v<std::string, T>)
inline VoidFunction SQMessageBufferPushArg(T& arg) {
auto converted = std::string(arg);
return [converted]{ g_pSquirrel<context>->pushstring(g_pSquirrel<context>->m_pSQVM->sqvm, converted.c_str(), converted.length()); };
return [converted]{ g_pSquirrel<context>->pushstring(g_pSquirrel<context>->m_pSQVM->sqvm, converted.c_str(), (int)converted.length()); };
}
// Assets
template <ScriptContext context>

View File

@ -52,12 +52,12 @@ void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name)
void TryPrintCvarHelpForCommand(const char* pCommand)
{
// try to display help text for an inputted command string from the console
int pCommandLen = strlen(pCommand);
size_t pCommandLen = strlen(pCommand);
char* pCvarStr = new char[pCommandLen];
strcpy(pCvarStr, pCommand);
// trim whitespace from right
for (int i = pCommandLen - 1; i; i--)
for (size_t i = pCommandLen - 1; i; i--)
{
if (isspace(pCvarStr[i]))
pCvarStr[i] = '\0';

View File

@ -136,9 +136,9 @@ int, __fastcall, (const char *const cmdname, const char *const partial, char com
RefreshMapList();
// use a custom autocomplete func for all map loading commands
const int cmdLength = strlen(cmdname);
const size_t cmdLength = strlen(cmdname);
const char* query = partial + cmdLength;
const int queryLength = strlen(query);
const size_t queryLength = strlen(query);
int numMaps = 0;
for (int i = 0; i < vMapList.size() && numMaps < COMMAND_COMPLETION_MAXITEMS; i++)

View File

@ -54,7 +54,7 @@ bool LoadNorthstar()
std::string cla = std::string(clachar);
if (strncmp(cla.substr(9, 1).c_str(), "\"", 1))
{
int space = cla.find(" ");
size_t space = cla.find(" ");
std::string dirname = cla.substr(9, space - 9);
std::cout << "[*] Found profile in command line arguments: " << dirname << std::endl;
strProfile = dirname.c_str();
@ -62,8 +62,8 @@ bool LoadNorthstar()
else
{
std::string quote = "\"";
int quote1 = cla.find(quote);
int quote2 = (cla.substr(quote1 + 1)).find(quote);
size_t quote1 = cla.find(quote);
size_t quote2 = (cla.substr(quote1 + 1)).find(quote);
std::string dirname = cla.substr(quote1 + 1, quote2);
std::cout << "[*] Found profile in command line arguments: " << dirname << std::endl;
strProfile = dirname;