diff --git a/rehlds/HLTV/Console/src/System.cpp b/rehlds/HLTV/Console/src/System.cpp index 07eb3db..9f70cdc 100644 --- a/rehlds/HLTV/Console/src/System.cpp +++ b/rehlds/HLTV/Console/src/System.cpp @@ -55,7 +55,7 @@ void Sys_Printf(char *fmt, ...) static char string[8192]; va_start(argptr, fmt); - _vsnprintf(string, sizeof(string), fmt, argptr); + Q_vsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); // Get Current text and append it. @@ -78,7 +78,7 @@ void System::RedirectOutput(char *buffer, int maxSize) m_RedirectSize = maxSize; if (m_RedirectBuffer) { - memset(m_RedirectBuffer, 0, m_RedirectSize); + Q_memset(m_RedirectBuffer, 0, m_RedirectSize); } } @@ -88,13 +88,13 @@ void System::Printf(char *fmt, ...) static char string[8192]; va_start(argptr, fmt); - _vsnprintf(string, sizeof(string), fmt, argptr); + Q_vsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); Log(string); - if (m_RedirectBuffer && strlen(string) + strlen(m_RedirectBuffer) + 1 < m_RedirectSize) { - strcat(m_RedirectBuffer, string); + if (m_RedirectBuffer && Q_strlen(string) + Q_strlen(m_RedirectBuffer) + 1 < m_RedirectSize) { + Q_strcat(m_RedirectBuffer, string); } m_Console.Print(string); @@ -107,11 +107,11 @@ void System::DPrintf(char *fmt, ...) va_start(argptr, fmt); if (m_Developer) { - _vsnprintf(string, sizeof(string), fmt, argptr); + Q_vsnprintf(string, sizeof(string), fmt, argptr); Log(string); - if (m_RedirectBuffer && strlen(string) + strlen(m_RedirectBuffer) + 1 < m_RedirectSize) { - strcat(m_RedirectBuffer, string); + if (m_RedirectBuffer && Q_strlen(string) + Q_strlen(m_RedirectBuffer) + 1 < m_RedirectSize) { + Q_strcat(m_RedirectBuffer, string); } m_Console.Print(string); @@ -133,7 +133,7 @@ bool System::RegisterCommand(char *name, ISystemModule *module, int commandID) command_t *cmd = (command_t *)m_Commands.GetFirst(); while (cmd) { - if (_stricmp(cmd->name, name) == 0) { + if (Q_stricmp(cmd->name, name) == 0) { Printf("WARNING! System::RegisterCommand: command \"%s\" already exists.\n", name); return false; } @@ -202,7 +202,7 @@ void System::Errorf(char *fmt, ...) va_list argptr; static char string[1024]; va_start(argptr, fmt); - _vsnprintf(string, sizeof(string), fmt, argptr); + Q_vsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); Printf("***** FATAL ERROR *****\n"); @@ -225,8 +225,8 @@ ISystemModule *System::FindModule(char *type, char *name) ISystemModule *module = (ISystemModule *)m_Modules.GetFirst(); while (module) { - if (_stricmp(type, module->GetType()) == 0 - && (!name || _stricmp(name, module->GetType()) == 0)) { + if (Q_stricmp(type, module->GetType()) == 0 + && (!name || Q_stricmp(name, module->GetType()) == 0)) { return module; } @@ -315,11 +315,11 @@ bool System::RemoveModule(ISystemModule *module) void System::GetCommandMatches(char *string, ObjectList *pMatchList) { - int len = strlen(string); + int len = Q_strlen(string); command_t *cmd = (command_t *)m_Commands.GetFirst(); while (cmd) { - if (!strncmp(cmd->name, string, len)) { + if (!Q_strncmp(cmd->name, string, len)) { pMatchList->AddTail(cmd); } @@ -375,8 +375,8 @@ bool System::Init(IBaseSystem *system, int serial, char *name) m_Libraries.Init(); m_LogFile = nullptr; - memset(m_LogFileName, 0, sizeof(m_LogFileName)); - memset(m_Factorylist, 0, sizeof(m_Factorylist)); + Q_memset(m_LogFileName, 0, sizeof(m_LogFileName)); + Q_memset(m_Factorylist, 0, sizeof(m_Factorylist)); m_RedirectBuffer = nullptr; m_RedirectSize = 0; @@ -395,7 +395,7 @@ bool System::Init(IBaseSystem *system, int serial, char *name) } auto pszValue = CheckParam("-maxfps"); - SetFPS(pszValue ? (float)atof(pszValue) : 100); + SetFPS(pszValue ? (float)Q_atof(pszValue) : 100); for (auto& cmd : m_LocalCmdReg) { RegisterCommand(cmd.name, this, cmd.id); @@ -538,7 +538,7 @@ void System::RunFrame(double time) char *System::GetStatusLine() { static char string[80]; - sprintf(string, " Libraries %i, Modules %i, Commands %i.\n", m_Libraries.CountElements(), m_Modules.CountElements(), m_Commands.CountElements()); + Q_sprintf(string, " Libraries %i, Modules %i, Commands %i.\n", m_Libraries.CountElements(), m_Modules.CountElements(), m_Commands.CountElements()); return string; } @@ -702,7 +702,7 @@ void System::CMD_Logfile(char *cmdLine) } char filename[MAX_PATH]; - sprintf(filename, "logfile%s.txt", COM_TimeString()); + Q_sprintf(filename, "logfile%s.txt", COM_TimeString()); OpenLogFile(filename); break; } @@ -765,7 +765,7 @@ void System::CMD_Developer(char *cmdLine) return; } - m_Developer = atoi(params.GetToken(1)) ? true : false; + m_Developer = Q_atoi(params.GetToken(1)) ? true : false; } void System::CMD_Quit(char *cmdLine) @@ -781,7 +781,7 @@ void System::OpenLogFile(char *filename) m_LogFile = m_FileSystem->Open(m_LogFileName, "wt"); if (!m_LogFile) { - memset(m_LogFileName, 0, sizeof(m_LogFileName)); + Q_memset(m_LogFileName, 0, sizeof(m_LogFileName)); Printf("System::OpenLogFile: error while opening logfile.\n"); } } @@ -796,7 +796,7 @@ void System::CloseLogFile() m_LogFile = nullptr; Printf("Console log file closed.\n"); - memset(m_LogFileName, 0, sizeof(m_LogFileName)); + Q_memset(m_LogFileName, 0, sizeof(m_LogFileName)); } void System::Log(char *string) @@ -804,7 +804,7 @@ void System::Log(char *string) if (!m_LogFile) return; - m_FileSystem->Write(string, strlen(string), m_LogFile); + m_FileSystem->Write(string, Q_strlen(string), m_LogFile); } void System::ExecuteFile(char *filename) @@ -821,7 +821,7 @@ void System::ExecuteFile(char *filename) Printf("Executing file %s.\n", filename); while ((m_FileSystem->ReadLine(line, sizeof(line) - 1, cfgfile))) { - char *remark = strstr(line, "//"); + char *remark = Q_strstr(line, "//"); if (remark) { *remark = '\0'; } @@ -841,7 +841,7 @@ bool System::DispatchCommand(char *command) command_t *cmd = (command_t *)m_Commands.GetFirst(); while (cmd) { - if (_stricmp(cmd->name, params.GetToken(0)) == 0) { + if (Q_stricmp(cmd->name, params.GetToken(0)) == 0) { cmd->module->ExecuteCommand(cmd->commandID, command); return true; } @@ -865,15 +865,15 @@ void System::ExecuteCommandLine() continue; } - memset(string, 0, sizeof(string)); + Q_memset(string, 0, sizeof(string)); Q_strlcpy(string, token + 1); // next iteration token = m_Parameters.GetToken(++i); while (token && !(token[0] == '+' || token[0] == '-')) { - strncat(string, " ", (sizeof(string) - 1) - strlen(string)); - strncat(string, token, (sizeof(string) - 1) - strlen(string)); + Q_strlcat(string, " "); + Q_strlcat(string, token); token = m_Parameters.GetToken(++i); } @@ -948,7 +948,7 @@ System::library_t *System::GetLibrary(char *name) library_t *lib = (library_t *)m_Libraries.GetFirst(); while (lib) { - if (_stricmp(lib->name, name) == 0) { + if (Q_stricmp(lib->name, name) == 0) { return lib; } @@ -961,7 +961,7 @@ System::library_t *System::GetLibrary(char *name) return nullptr; } - _snprintf(lib->name, sizeof(lib->name), "%s." LIBRARY_PREFIX, fixedname); + Q_snprintf(lib->name, sizeof(lib->name), "%s." LIBRARY_PREFIX, fixedname); lib->handle = (CSysModule *)Sys_LoadModule(lib->name); if (!lib->handle) { DPrintf("WARNING! System::GetLibrary: coulnd't load library (%s).\n", lib->name); @@ -1111,7 +1111,7 @@ void System::Sleep(int msec) int main(int argc, char *argv[]) { gSystem.BuildCommandLine(argc, argv); - _snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]); + Q_snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]); return gSystem.Run(); } @@ -1124,13 +1124,13 @@ void System::BuildCommandLine(int argc, char **argv) for (int i = 1; i < argc && len < MAX_LINUX_CMDLINE; i++) { - len += strlen(argv[i]) + 1; + len += Q_strlen(argv[i]) + 1; if (i > 1) { - strcat(string, " "); + Q_strlcat(string, " "); } - strcat(string, argv[i]); + Q_strlcat(string, argv[i]); } m_Parameters.SetLine(string); diff --git a/rehlds/HLTV/Core/src/BSPModel.cpp b/rehlds/HLTV/Core/src/BSPModel.cpp index 5bf4328..01c70f2 100644 --- a/rehlds/HLTV/Core/src/BSPModel.cpp +++ b/rehlds/HLTV/Core/src/BSPModel.cpp @@ -37,8 +37,8 @@ void BSPModel::Init(IBaseSystem *system) m_wadpath = nullptr; m_IsMinimal = false; - memset(&m_model, 0, sizeof(m_model)); - memset(m_novis, 0xFF, sizeof(m_novis)); + Q_memset(&m_model, 0, sizeof(m_model)); + Q_memset(m_novis, 0xFF, sizeof(m_novis)); } bool BSPModel::Load(const char *name, bool minimal) @@ -192,7 +192,7 @@ void BSPModel::DecompressPVS(unsigned char *in, unsigned char *decompressed, int if (in == nullptr) { // Make all visible - memcpy(decompressed, m_novis, byteCount); + Q_memcpy(decompressed, m_novis, byteCount); return; } @@ -216,7 +216,7 @@ void BSPModel::DecompressPVS(unsigned char *in, unsigned char *decompressed, int } // Unpack zeros - memset(out, 0, c); + Q_memset(out, 0, c); out += c; } } @@ -372,7 +372,7 @@ void BSPModel::LoadVisibility(lump_t *l) return; } - memcpy(m_model.visdata, m_base + l->fileofs, l->filelen); + Q_memcpy(m_model.visdata, m_base + l->fileofs, l->filelen); } bool BSPModel::IsValid() @@ -445,7 +445,7 @@ void BSPModel::Clear() Free(m_wadpath); - memset(&m_model, 0, sizeof(m_model)); + Q_memset(&m_model, 0, sizeof(m_model)); m_visframecount = 0; m_wadpath = nullptr; @@ -536,7 +536,7 @@ void BSPModel::MakeHull0() bool BSPModel::TraceLine(vec_t *start, vec_t *end, vec_t *impact) { trace_t trace; - memset(&trace, 0, sizeof(trace)); + Q_memset(&trace, 0, sizeof(trace)); auto res = RecursiveHullCheck(m_model.hulls, 0, 0, 1, start, end, &trace); VectorCopy(trace.endpos, impact); return res; @@ -594,7 +594,7 @@ bool BSPModel::RecursiveHullCheck(hull_t *hull, int num, float p1f, float p2f, v } midf = midf / (t1 - t2); - midf = clamp(midf, 0.0f, 1.0f); + midf = Q_clamp(midf, 0.0f, 1.0f); // not a number if (!IS_NAN(midf)) @@ -836,21 +836,21 @@ void BSPModel::LoadEntities(lump_t *l) } m_model.entities = (char *)Mem_ZeroMalloc(l->filelen); - memcpy(m_model.entities, (const void *)(m_base + l->fileofs), l->filelen); + Q_memcpy(m_model.entities, (const void *)(m_base + l->fileofs), l->filelen); char *pszInputStream = COM_Parse(m_model.entities); if (*pszInputStream) { while (com_token[0] != '}') { - if (!strcmp(com_token, "wad")) + if (!Q_strcmp(com_token, "wad")) { COM_Parse(pszInputStream); if (m_wadpath) { Mem_Free(m_wadpath); } - m_wadpath = _strdup(com_token); + m_wadpath = Q_strdup(com_token); return; } @@ -866,7 +866,7 @@ void BSPModel::LoadLighting(lump_t *l) if (l->filelen) { m_model.lightdata = (color24 *)Mem_ZeroMalloc(l->filelen); - memcpy(m_model.lightdata, (const void *)(m_base + l->fileofs), l->filelen); + Q_memcpy(m_model.lightdata, (const void *)(m_base + l->fileofs), l->filelen); } else { @@ -923,12 +923,12 @@ void BSPModel::LoadFaces(lump_t *l) { // set the drawing flags flag const char *texName = out->texinfo->texture->name; - if (!strncmp(texName, "sky", 3)) { + if (!Q_strncmp(texName, "sky", 3)) { out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED); continue; } - if (!strncmp(texName, "aaatrigger", 10)) { + if (!Q_strncmp(texName, "aaatrigger", 10)) { out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED); continue; } @@ -1153,9 +1153,9 @@ void BSPModel::LoadTextures(lump_t *l) tx = (texture_t *)Mem_ZeroMalloc(85 * pixels + 66); m_model.textures[i] = tx; - memcpy(tx->name, mt->name, sizeof(tx->name)); + Q_memcpy(tx->name, mt->name, sizeof(tx->name)); - if (strchr(tx->name, '~')) { + if (Q_strchr(tx->name, '~')) { tx->name[2] = ' '; } diff --git a/rehlds/HLTV/Core/src/Delta.cpp b/rehlds/HLTV/Core/src/Delta.cpp index 7fc1e2d..a1e5d75 100644 --- a/rehlds/HLTV/Core/src/Delta.cpp +++ b/rehlds/HLTV/Core/src/Delta.cpp @@ -331,7 +331,7 @@ delta_description_t *Delta::FindField(delta_t *pFields, const char *pszField) { for (int i = 0; i < pFields->fieldCount; i++) { - if (_stricmp(pFields->pdd[i].fieldName, pszField) == 0) { + if (Q_stricmp(pFields->pdd[i].fieldName, pszField) == 0) { return &pFields->pdd[i]; } } @@ -345,7 +345,7 @@ delta_t **Delta::LookupRegistration(char *name) delta_registry_t *delta = m_DeltaRegistry; while (delta) { - if (_stricmp(delta->name, name) == 0) { + if (Q_stricmp(delta->name, name) == 0) { return &delta->pdesc; } @@ -359,7 +359,7 @@ int Delta::FindFieldIndex(delta_t *pFields, const char *fieldname) { for (int i = 0; i < pFields->fieldCount; i++) { - if (_stricmp(pFields->pdd[i].fieldName, fieldname) == 0) { + if (Q_stricmp(pFields->pdd[i].fieldName, fieldname) == 0) { return i; } } @@ -453,7 +453,7 @@ void Delta::MarkSendFields(unsigned char *from, unsigned char *to, delta_t *pFie st2 = (char *)&to[pTest->fieldOffset]; // Not sure why it is case insensitive, but it looks so - if (!(!*st1 && !*st2 || *st1 && *st2 && !_stricmp(st1, st2))) { + if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) { pTest->flags |= FDT_MARK; } break; @@ -474,7 +474,7 @@ void Delta::SetSendFlagBits(delta_t *pFields, int *bits, int *bytecount) int lastbit = -1; int fieldCount = pFields->fieldCount; - memset(bits, 0, 8); + Q_memset(bits, 0, 8); for (i = fieldCount - 1; i >= 0; i--) { @@ -737,7 +737,7 @@ int Delta::ParseDelta(BitBuffer *stream, unsigned char *from, unsigned char *to, int startbit; startbit = stream->CurrentBit(); - memset(bits, 0, sizeof(bits)); + Q_memset(bits, 0, sizeof(bits)); nbytes = stream->ReadBits(3); for (i = 0; i < nbytes; i++) { @@ -768,7 +768,7 @@ int Delta::ParseDelta(BitBuffer *stream, unsigned char *from, unsigned char *to, *(uint32 *)&to[pTest->fieldOffset] = *(uint32 *)&from[pTest->fieldOffset]; break; case DT_STRING: - strcpy((char *)&to[pTest->fieldOffset], (char *)&from[pTest->fieldOffset]); + Q_strcpy((char *)&to[pTest->fieldOffset], (char *)&from[pTest->fieldOffset]); break; default: m_System->Printf("Delta::ParseDelta: unparseable field type %i\n", fieldType); @@ -972,10 +972,10 @@ int Delta::TestDelta(unsigned char *from, unsigned char *to, delta_t *pFields) st2 = (char *)&to[pTest->fieldOffset]; // Not sure why it is case insensitive, but it looks so - if (!(!*st1 && !*st2 || *st1 && *st2 && !_stricmp(st1, st2))) + if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) { different = true; - length = strlen(st2) * 8; + length = Q_strlen(st2) * 8; pTest->flags |= FDT_MARK; } break; @@ -1001,7 +1001,7 @@ int Delta::TestDelta(unsigned char *from, unsigned char *to, delta_t *pFields) void Delta::AddEncoder(char *name, encoder_t conditionalencode) { delta_encoder_t *delta = (delta_encoder_t *)Mem_ZeroMalloc(sizeof(delta_encoder_t)); - delta->name = _strdup(name); + delta->name = Q_strdup(name); delta->conditionalencode = conditionalencode; delta->next = m_Encoders; m_Encoders = delta; @@ -1026,7 +1026,7 @@ encoder_t Delta::LookupEncoder(char *name) delta_encoder_t *p = m_Encoders; while (p) { - if (_stricmp(name, p->name) == 0) { + if (Q_stricmp(name, p->name) == 0) { return p->conditionalencode; } @@ -1096,7 +1096,7 @@ delta_t *Delta::BuildFromLinks(delta_link_t **pplinks) for (p = *pplinks, pcur = pdesc; p; p = p->next, pcur++) { - memcpy(pcur, p->delta, sizeof(delta_description_t)); + Q_memcpy(pcur, p->delta, sizeof(delta_description_t)); Mem_Free(p->delta); p->delta = 0; } @@ -1114,7 +1114,7 @@ int Delta::FindOffset(int count, delta_definition_t *pdef, char *fieldname) { for (int i = 0; i < count; i++) { - if (_stricmp(fieldname, pdef[i].fieldName) == 0) { + if (Q_stricmp(fieldname, pdef[i].fieldName) == 0) { return pdef[i].fieldOffset; } } @@ -1128,30 +1128,30 @@ bool Delta::ParseType(delta_description_t *pdelta, char **pstream) // Read the stream till we hit the end while (*pstream = COM_Parse(*pstream), com_token[0] != 0) { - if (!_stricmp(com_token, ",")) + if (!Q_stricmp(com_token, ",")) return true; // end of type description - if (!_stricmp(com_token, "|")) + if (!Q_stricmp(com_token, "|")) continue; // skip | token // Determine field type - if (!_stricmp(com_token, "DT_SIGNED")) + if (!Q_stricmp(com_token, "DT_SIGNED")) pdelta->fieldType |= DT_SIGNED; - else if (!_stricmp(com_token, "DT_BYTE")) + else if (!Q_stricmp(com_token, "DT_BYTE")) pdelta->fieldType |= DT_BYTE; - else if (!_stricmp(com_token, "DT_SHORT")) + else if (!Q_stricmp(com_token, "DT_SHORT")) pdelta->fieldType |= DT_SHORT; - else if (!_stricmp(com_token, "DT_FLOAT")) + else if (!Q_stricmp(com_token, "DT_FLOAT")) pdelta->fieldType |= DT_FLOAT; - else if (!_stricmp(com_token, "DT_INTEGER")) + else if (!Q_stricmp(com_token, "DT_INTEGER")) pdelta->fieldType |= DT_INTEGER; - else if (!_stricmp(com_token, "DT_ANGLE")) + else if (!Q_stricmp(com_token, "DT_ANGLE")) pdelta->fieldType |= DT_ANGLE; - else if (!_stricmp(com_token, "DT_TIMEWINDOW_8")) + else if (!Q_stricmp(com_token, "DT_TIMEWINDOW_8")) pdelta->fieldType |= DT_TIMEWINDOW_8; - else if (!_stricmp(com_token, "DT_TIMEWINDOW_BIG")) + else if (!Q_stricmp(com_token, "DT_TIMEWINDOW_BIG")) pdelta->fieldType |= DT_TIMEWINDOW_BIG; - else if (!_stricmp(com_token, "DT_STRING")) + else if (!Q_stricmp(com_token, "DT_STRING")) pdelta->fieldType |= DT_STRING; else { @@ -1168,9 +1168,9 @@ bool Delta::ParseType(delta_description_t *pdelta, char **pstream) bool Delta::ParseField(int count, delta_definition_t *pdefinition, delta_link_t *pField, char **pstream) { bool readpost = false; - if (_stricmp(com_token, "DEFINE_DELTA")) + if (Q_stricmp(com_token, "DEFINE_DELTA")) { - if (_stricmp(com_token, "DEFINE_DELTA_POST") != 0) { + if (Q_stricmp(com_token, "DEFINE_DELTA_POST") != 0) { m_System->Errorf("Delta::ParseField: Expecting DEFINE_*, got %s\n", com_token); return false; } @@ -1179,7 +1179,7 @@ bool Delta::ParseField(int count, delta_definition_t *pdefinition, delta_link_t } *pstream = COM_Parse(*pstream); - if (_stricmp(com_token, "(")) + if (Q_stricmp(com_token, "(")) { m_System->Errorf("Delta::ParseField: Expecting (, got %s\n", com_token); return false; @@ -1202,16 +1202,16 @@ bool Delta::ParseField(int count, delta_definition_t *pdefinition, delta_link_t *pstream = COM_Parse(*pstream); pField->delta->fieldSize = 1; - pField->delta->significant_bits = atoi(com_token); + pField->delta->significant_bits = Q_atoi(com_token); *pstream = COM_Parse(*pstream); *pstream = COM_Parse(*pstream); - pField->delta->premultiply = (float)atof(com_token); + pField->delta->premultiply = (float)Q_atof(com_token); if (readpost) { *pstream = COM_Parse(*pstream); *pstream = COM_Parse(*pstream); - pField->delta->postmultiply = (float)atof(com_token); + pField->delta->postmultiply = (float)Q_atof(com_token); } else { @@ -1219,14 +1219,14 @@ bool Delta::ParseField(int count, delta_definition_t *pdefinition, delta_link_t } *pstream = COM_Parse(*pstream); - if (_stricmp(com_token, ")")) + if (Q_stricmp(com_token, ")")) { m_System->Printf("Delta::ParseField: Expecting ), got %s\n", com_token); return false; } *pstream = COM_Parse(*pstream); - if (_stricmp(com_token, ",")) { + if (Q_stricmp(com_token, ",")) { COM_UngetToken(); } @@ -1251,7 +1251,7 @@ void Delta::AddDefinition(char *name, delta_definition_t *pdef, int numelements) delta_definition_list_t *p = m_Defs; while (p) { - if (_stricmp(name, p->ptypename) == 0) { + if (Q_stricmp(name, p->ptypename) == 0) { break; } @@ -1261,7 +1261,7 @@ void Delta::AddDefinition(char *name, delta_definition_t *pdef, int numelements) if (!p) { p = (delta_definition_list_t *)Mem_ZeroMalloc(sizeof(delta_definition_list_t)); - p->ptypename = _strdup(name); + p->ptypename = Q_strdup(name); p->next = m_Defs; m_Defs = p; } @@ -1291,7 +1291,7 @@ Delta::delta_definition_t *Delta::FindDefinition(char *name, int *count) delta_definition_list_t *p = m_Defs; while (p) { - if (!_stricmp(name, p->ptypename)) + if (!Q_stricmp(name, p->ptypename)) { *count = p->numelements; return p->pdefinition; @@ -1314,7 +1314,7 @@ void Delta::SkipDescription(char **pstream) return; } } - while (_stricmp(com_token, "}")); + while (Q_stricmp(com_token, "}")); } bool Delta::ParseOneField(char **ppstream, delta_link_t **pplist, int count, delta_definition_t *pdefinition) @@ -1324,7 +1324,7 @@ bool Delta::ParseOneField(char **ppstream, delta_link_t **pplist, int count, del while (true) { - if (!_stricmp(com_token, "}")) + if (!Q_stricmp(com_token, "}")) { COM_UngetToken(); break; @@ -1335,7 +1335,7 @@ bool Delta::ParseOneField(char **ppstream, delta_link_t **pplist, int count, del break; } - memset(&link, 0, sizeof(link)); + Q_memset(&link, 0, sizeof(link)); link.delta = (delta_description_t *)Mem_ZeroMalloc(sizeof(delta_description_t)); if (!ParseField(count, pdefinition, &link, ppstream)) { return false; @@ -1378,7 +1378,7 @@ bool Delta::ParseDescription(char *name, delta_t **ppdesc, char *pstream) break; } - if (_stricmp(com_token, name)) + if (Q_stricmp(com_token, name)) { SkipDescription(&pstream); } @@ -1397,7 +1397,7 @@ bool Delta::ParseDescription(char *name, delta_t **ppdesc, char *pstream) return false; } - if (_stricmp(com_token, "none")) + if (Q_stricmp(com_token, "none")) { Q_strlcpy(source, com_token); @@ -1419,11 +1419,11 @@ bool Delta::ParseDescription(char *name, delta_t **ppdesc, char *pstream) break; } - if (!_stricmp(com_token, "}")) { + if (!Q_stricmp(com_token, "}")) { break; } - if (_stricmp(com_token, "{")) { + if (Q_stricmp(com_token, "{")) { m_System->Printf("Delta::ParseDescription: Expecting {, got %s\n", com_token); return false; } @@ -1465,7 +1465,7 @@ void Delta::RegisterDescription(char *name) delta_registry_t *p = (delta_registry_t *)Mem_ZeroMalloc(sizeof(delta_registry_t)); p->next = m_DeltaRegistry; m_DeltaRegistry = p; - p->name = _strdup(name); + p->name = Q_strdup(name); p->pdesc = 0; } diff --git a/rehlds/HLTV/Core/src/NetSocket.cpp b/rehlds/HLTV/Core/src/NetSocket.cpp index 2ba4eed..263dc73 100644 --- a/rehlds/HLTV/Core/src/NetSocket.cpp +++ b/rehlds/HLTV/Core/src/NetSocket.cpp @@ -314,7 +314,7 @@ int NetSocket::GetLong(unsigned char *pData, int size) netSplitFlags[packetNumber] = sequenceNumber; } - memcpy(&m_NetSplitPacket.buffer[SPLIT_SIZE * packetNumber], pHeader + 1, packetPayloadSize); + Q_memcpy(&m_NetSplitPacket.buffer[SPLIT_SIZE * packetNumber], pHeader + 1, packetPayloadSize); if (m_NetSplitPacket.splitCount > 0) { return 0; @@ -328,7 +328,7 @@ int NetSocket::GetLong(unsigned char *pData, int size) } - memcpy(pData, m_NetSplitPacket.buffer, m_NetSplitPacket.totalSize); + Q_memcpy(pData, m_NetSplitPacket.buffer, m_NetSplitPacket.totalSize); return m_NetSplitPacket.totalSize; } @@ -340,10 +340,10 @@ void NetSocket::OutOfBandPrintf(NetAddress *to, const char *format, ...) *(int *)string = CONNECTIONLESS_HEADER; va_start(argptr, format); - _vsnprintf(&string[4], sizeof(string) - 4, format, argptr); + Q_vsnprintf(&string[4], sizeof(string) - 4, format, argptr); va_end(argptr); - SendPacket(to, string, strlen(string) + 1); + SendPacket(to, string, Q_strlen(string) + 1); } void NetSocket::GetFlowStats(float *avgInKBSec, float *avgOutKBSec) @@ -412,8 +412,8 @@ bool NetSocket::Create(Network *network, int port, bool reuse, bool loopback) m_Channels.Init(); - memset(m_Buffer, 0, sizeof(m_Buffer)); - memset(&m_NetSplitPacket, 0, sizeof(m_NetSplitPacket)); + Q_memset(m_Buffer, 0, sizeof(m_Buffer)); + Q_memset(&m_NetSplitPacket, 0, sizeof(m_NetSplitPacket)); if ((m_Socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { return false; @@ -465,7 +465,7 @@ bool NetSocket::Create(Network *network, int port, bool reuse, bool loopback) uint32 ttl = 32; char *ttlparam = m_System->CheckParam("-multicastttl"); if (ttlparam) { - ttl = atoi(ttlparam); + ttl = Q_atoi(ttlparam); } if (setsockopt(m_Socket, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) == SOCKET_ERROR) { @@ -520,9 +520,9 @@ int NetSocket::SendLong(const char *pData, int len, int flags, const sockaddr *t while (len > 0) { - size = min(SPLIT_SIZE, (unsigned)len); + size = Q_min(SPLIT_SIZE, (unsigned)len); pPacket->packetID = (packetNumber << 4) + packetCount; - memcpy(packet + sizeof(SPLITPACKET), pData + (packetNumber * SPLIT_SIZE), size); + Q_memcpy(packet + sizeof(SPLITPACKET), pData + (packetNumber * SPLIT_SIZE), size); ret = sendto(m_Socket, packet, size + sizeof(SPLITPACKET), flags, to, tolen); if (ret < 0) { @@ -548,8 +548,8 @@ int NetSocket::SendShort(const char *pData, int len, int flags, const sockaddr * } char packet[MAX_ROUTEABLE_PACKET]; - memcpy(packet, pData, len); - memset(&packet[len], 0, sizeof(packet) - len); + Q_memcpy(packet, pData, len); + Q_memset(&packet[len], 0, sizeof(packet) - len); return sendto(m_Socket, packet, sizeof(packet), flags, to, tolen); } diff --git a/rehlds/HLTV/Core/src/Network.cpp b/rehlds/HLTV/Core/src/Network.cpp index 81b67d0..cf087d1 100644 --- a/rehlds/HLTV/Core/src/Network.cpp +++ b/rehlds/HLTV/Core/src/Network.cpp @@ -85,7 +85,7 @@ bool Network::Init(IBaseSystem *system, int serial, char *name) portparam = "27020"; } - m_LocalAddress.m_Port = htons(atoi(portparam)); + m_LocalAddress.m_Port = htons(Q_atoi(portparam)); m_LastStatsUpdateTime = 0; m_State = MODULE_RUNNING; @@ -226,7 +226,7 @@ char *Network::GetStatusLine() float in, out; GetFlowStats(&in, &out); - _snprintf(string, sizeof(string), "Local IP %s, Sockets %i, In %.2f, Out %.2f.\n", m_LocalAddress.ToBaseString(), m_Sockets.CountElements(), in, out); + Q_snprintf(string, sizeof(string), "Local IP %s, Sockets %i, In %.2f, Out %.2f.\n", m_LocalAddress.ToBaseString(), m_Sockets.CountElements(), in, out); return string; } @@ -257,7 +257,7 @@ void Network::CMD_FakeLoss(char *cmdLine) return; } - m_FakeLoss = atof(params.GetToken(1)); + m_FakeLoss = Q_atof(params.GetToken(1)); } int Network::GetLastErrorCode() @@ -273,11 +273,11 @@ bool Network::ResolveAddress(char *string, NetAddress *address) address->Clear(); - if (!string || !strlen(string)) { + if (!string || !Q_strlen(string)) { return 0; } - memset(&sadr, 0, sizeof(sadr)); + Q_memset(&sadr, 0, sizeof(sadr)); ((sockaddr_in *)&sadr)->sin_family = AF_INET; ((sockaddr_in *)&sadr)->sin_port = 0; @@ -290,7 +290,7 @@ bool Network::ResolveAddress(char *string, NetAddress *address) if (*colon == ':') { *colon = '\0'; - int val = atoi(colon + 1); + int val = Q_atoi(colon + 1); ((sockaddr_in *)&sadr)->sin_port = htons(val); } colon++; @@ -298,7 +298,7 @@ bool Network::ResolveAddress(char *string, NetAddress *address) // Parse address // Validate IPv4 - if (copy[0] >= '0' && copy[0] <= '9' && strstr(copy, ".")) + if (copy[0] >= '0' && copy[0] <= '9' && Q_strstr(copy, ".")) { uint32 ret = inet_addr(copy); if (ret == INADDR_NONE) { diff --git a/rehlds/HLTV/Core/src/Server.cpp b/rehlds/HLTV/Core/src/Server.cpp index d166e0e..3e8c407 100644 --- a/rehlds/HLTV/Core/src/Server.cpp +++ b/rehlds/HLTV/Core/src/Server.cpp @@ -132,7 +132,7 @@ bool Server::Init(IBaseSystem *system, int serial, char *name) m_ClientData.Resize(MAX_UDP_PACKET); m_DemoData.Resize(MAX_UDP_PACKET); - memset(&m_Frame, 0, sizeof(m_Frame)); + Q_memset(&m_Frame, 0, sizeof(m_Frame)); m_Frame.reliableData = m_ReliableData.GetData(); m_Frame.unreliableData = m_UnreliableData.GetData(); @@ -151,7 +151,7 @@ bool Server::Init(IBaseSystem *system, int serial, char *name) Q_strlcpy(m_CDKey, "2123437429222"); Q_strlcpy(m_HostName, "Unkown Host"); - memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); + Q_memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); m_validSequence = 0; m_AutoRetry = true; m_IsHLTV = true; @@ -174,13 +174,13 @@ void Server::SetGameDirectory(const char *defaultDir, const char *gameDir) char temp[MAX_PATH]; m_FileSystem->RemoveAllSearchPaths(); - if (gameDir && _stricmp(gameDir, defaultDir) != 0) + if (gameDir && Q_stricmp(gameDir, defaultDir) != 0) { - sprintf(temp, "%s/%s", m_System->GetBaseDir(), gameDir); + Q_sprintf(temp, "%s/%s", m_System->GetBaseDir(), gameDir); m_FileSystem->AddSearchPath(temp, "GAME"); } - sprintf(temp, "%s/%s", m_System->GetBaseDir(), defaultDir); + Q_sprintf(temp, "%s/%s", m_System->GetBaseDir(), defaultDir); m_FileSystem->AddSearchPath(temp, "DEFAULTGAME"); m_FileSystem->AddSearchPath(m_System->GetBaseDir(), "ROOT"); } @@ -451,8 +451,8 @@ void Server::AcceptChallenge(char *cmdLine) return; } - m_ChallengeNumber = atoi(params.GetToken(1)); - m_AuthProtocol = atoi(params.GetToken(2)); + m_ChallengeNumber = Q_atoi(params.GetToken(1)); + m_AuthProtocol = Q_atoi(params.GetToken(2)); m_AuthProtocol = 2; if (m_AuthProtocol == 2) @@ -480,13 +480,13 @@ void Server::SetVoiceBlocking(bool state) void Server::SetRate(int rate) { - m_Rate = clamp(rate, 1000, MAX_SERVER_RATE); + m_Rate = Q_clamp(rate, 1000, MAX_SERVER_RATE); SetUserInfo("rate", COM_VarArgs("%i", m_Rate)); } void Server::SetUpdateRate(int updaterate) { - m_UpdateRate = clamp(updaterate, 1, MAX_SERVER_UPDATERATE); + m_UpdateRate = Q_clamp(updaterate, 1, MAX_SERVER_UPDATERATE); SetUserInfo("cl_updaterate", COM_VarArgs("%i", m_UpdateRate)); } @@ -623,8 +623,8 @@ void Server::SendConnectPacket() protinfo.SetValueForKey("cdkey", MD5_GetCDKeyHash(m_CDKey)); } - _snprintf(data, sizeof(data), "%c%c%c%cconnect %i %i \"%s\" \"%s\"\n", 0xFF, 0xFF, 0xFF, 0xFF, m_Protocol, m_ChallengeNumber, protinfo.GetString(), m_UserInfo.GetString()); - m_ServerSocket->SendPacket(m_ServerChannel.GetTargetAddress(), data, strlen(data)); + Q_snprintf(data, sizeof(data), "%c%c%c%cconnect %i %i \"%s\" \"%s\"\n", 0xFF, 0xFF, 0xFF, 0xFF, m_Protocol, m_ChallengeNumber, protinfo.GetString(), m_UserInfo.GetString()); + m_ServerSocket->SendPacket(m_ServerChannel.GetTargetAddress(), data, Q_strlen(data)); m_System->Printf("Connecting to %s (%i/%i).\n", m_ServerChannel.GetTargetAddress()->ToString(), m_CurrentRetry, MAX_CONNECT_RETRIES); nextRetry = m_SystemTime + CONNECT_RETRY_INTERVAL; @@ -702,7 +702,7 @@ void Server::ParseVoiceInit() char *codec = m_Instream->ReadString(); unsigned char quality = m_Instream->ReadByte(); - int length = strlen(codec); + int length = Q_strlen(codec); if (m_ServerState == SERVER_CONNECTED) { m_World->AddSignonData(svc_voiceinit, start, length + 2); } @@ -967,7 +967,7 @@ void Server::ParseStuffText() return; } - if (!_stricmp(cmd, "fullserverinfo")) + if (!Q_stricmp(cmd, "fullserverinfo")) { char *infostring = cmdLine.GetToken(1); m_ServerInfo.SetString(infostring); @@ -998,7 +998,7 @@ void Server::ParseStuffText() BaseSystemModule::FireSignal(4); return; } - else if (!_stricmp(cmd, "reconnect")) + else if (!Q_stricmp(cmd, "reconnect")) { if (IsDemoFile()) { @@ -1017,7 +1017,7 @@ void Server::ParseStuffText() m_IsPaused = false; return; } - else if (!_stricmp(cmd, "connect")) + else if (!Q_stricmp(cmd, "connect")) { if (m_ServerSocket && m_World) { @@ -1035,18 +1035,18 @@ void Server::ParseStuffText() return; } - else if (!_stricmp(cmd, "rate") - || !_stricmp(cmd, "cl_updaterate") - || !_stricmp(cmd, "ex_interp") - || !_stricmp(cmd, "cl_cmdrate") - || !_stricmp(cmd, "cl_cmdbackup")) + else if (!Q_stricmp(cmd, "rate") + || !Q_stricmp(cmd, "cl_updaterate") + || !Q_stricmp(cmd, "ex_interp") + || !Q_stricmp(cmd, "cl_cmdrate") + || !Q_stricmp(cmd, "cl_cmdbackup")) { return; } if (m_ServerState == SERVER_CONNECTED) { - m_World->AddSignonData(svc_stufftext, (unsigned char *)cmdLine.GetLine(), strlen(cmdLine.GetLine()) + 1); + m_World->AddSignonData(svc_stufftext, (unsigned char *)cmdLine.GetLine(), Q_strlen(cmdLine.GetLine()) + 1); } else if (m_ServerState == SERVER_RUNNING || m_ServerState == SERVER_INTERMISSION) { @@ -1092,7 +1092,7 @@ void Server::ParseResourceList() for (int i = 0; i < total; i++) { resource_t resource; - memset(&resource, 0, sizeof(resource)); + Q_memset(&resource, 0, sizeof(resource)); resource.type = (resourcetype_t)m_Instream->ReadBits(4); @@ -1110,7 +1110,7 @@ void Server::ParseResourceList() m_Instream->ReadBitData(resource.rguc_reserved, sizeof(resource.rguc_reserved)); } - if (strncmp(resource.szFileName, "gfx/temp/", 9) != 0) { + if (Q_strncmp(resource.szFileName, "gfx/temp/", 9) != 0) { m_World->AddResource(&resource); } } @@ -1351,7 +1351,7 @@ void Server::ParseSignonNum() Q_strlcpy(string, "vban"); for (int i = 0; i < MAX_CLIENTS; i++) { - strcat(string, " 0"); + Q_strlcat(string, " 0"); } SendStringCommand(string); @@ -1414,7 +1414,7 @@ void Server::ClearFrame(bool completely) m_Frame.eventsSize = 0; m_Frame.demoInfo = 0; - memset(&m_DemoInfo, 0, sizeof(m_DemoInfo)); + Q_memset(&m_DemoInfo, 0, sizeof(m_DemoInfo)); m_Frame.unreliableDataSize = 0; m_Frame.voiceDataSize = 0; m_Frame.clientDataSize = 0; @@ -1462,25 +1462,25 @@ bool Server::ParseUserMessage(int cmd) m_System->Printf("WARNING! Server::ParseUserMessage: unexpected server state.\n"); } - if (!strcmp(usermsg->szName, "SayText")) + if (!Q_strcmp(usermsg->szName, "SayText")) { m_System->Printf("%s\n", start + 2); } - else if (!strcmp(usermsg->szName, "TextMsg")) + else if (!Q_strcmp(usermsg->szName, "TextMsg")) { m_System->DPrintf("%s\n", start + 2); } - else if (!strcmp(usermsg->szName, "ReqState")) + else if (!Q_strcmp(usermsg->szName, "ReqState")) { char cmdString[32]; - _snprintf(cmdString, sizeof(cmdString), "VModEnable %d", m_IsVoiceBlocking == 0); + Q_snprintf(cmdString, sizeof(cmdString), "VModEnable %d", m_IsVoiceBlocking == 0); SendStringCommand(cmdString); char string[128]; Q_strlcpy(string, "vban"); for (int i = 0; i < MAX_CLIENTS; i++) { - strcat(string, " 0"); + Q_strlcat(string, " 0"); } SendStringCommand(string); @@ -1503,7 +1503,7 @@ void Server::ParsePacketEntities() m_Frame.entitiesSize = sizeof(entity_state_t) * entnum; m_Frame.entities = m_EntityBuffer; - memset(m_EntityBuffer, 0, m_Frame.entitiesSize); + Q_memset(m_EntityBuffer, 0, m_Frame.entitiesSize); m_World->UncompressEntitiesFromStream(&m_Frame, m_Instream); } @@ -1518,7 +1518,7 @@ void Server::ParseDeltaPacketEntities() m_Frame.entitynum = entnum; m_Frame.entitiesSize = sizeof(entity_state_t) * entnum; m_Frame.entities = m_EntityBuffer; - memset(m_EntityBuffer, 0, m_Frame.entitiesSize); + Q_memset(m_EntityBuffer, 0, m_Frame.entitiesSize); int from = m_Instream->ReadByte(); if (!m_World->UncompressEntitiesFromStream(&m_Frame, m_Instream, m_SeqNrMap[from])) { @@ -1763,27 +1763,27 @@ char *Server::GetStatusLine() switch (m_ServerState) { case SERVER_INITIALIZING: - _snprintf(string, sizeof(string), "Initializing.\n"); + Q_snprintf(string, sizeof(string), "Initializing.\n"); break; case SERVER_DISCONNECTED: - _snprintf(string, sizeof(string), "Disconnected.\n"); + Q_snprintf(string, sizeof(string), "Disconnected.\n"); break; case SERVER_CHALLENGING: - _snprintf(string, sizeof(string), "challenging %s.\n", m_ServerChannel.GetTargetAddress()->ToString()); + Q_snprintf(string, sizeof(string), "challenging %s.\n", m_ServerChannel.GetTargetAddress()->ToString()); break; case SERVER_AUTHENTICATING: - _snprintf(string, sizeof(string), "Authenticating.\n"); + Q_snprintf(string, sizeof(string), "Authenticating.\n"); break; case SERVER_CONNECTING: - _snprintf(string, sizeof(string), "Connecting to %s.\n", m_ServerChannel.GetTargetAddress()->ToString()); + Q_snprintf(string, sizeof(string), "Connecting to %s.\n", m_ServerChannel.GetTargetAddress()->ToString()); break; case SERVER_CONNECTED: case SERVER_RUNNING: m_ServerChannel.GetFlowStats(&in, &out); - _snprintf(string, sizeof(string), "Connected to %s, Time %.0f, In %.2f, Out %.2f.\n", m_ServerChannel.GetTargetAddress()->ToString(), m_SystemTime - m_ServerChannel.m_connect_time, in, out); + Q_snprintf(string, sizeof(string), "Connected to %s, Time %.0f, In %.2f, Out %.2f.\n", m_ServerChannel.GetTargetAddress()->ToString(), m_SystemTime - m_ServerChannel.m_connect_time, in, out); break; case SERVER_INTERMISSION: - _snprintf(string, sizeof(string), "Intermission (%s).\n", m_ServerChannel.GetTargetAddress()->ToString()); + Q_snprintf(string, sizeof(string), "Intermission (%s).\n", m_ServerChannel.GetTargetAddress()->ToString()); break; default: m_System->Errorf("Server::GetStatusLine: not valid state.\n"); @@ -2021,7 +2021,7 @@ void Server::SendUserVar(char *key, char *value) if (*value) { - _snprintf(cmdString, sizeof(cmdString), "setinfo \"%s\" \"%s\"\n", key, value); + Q_snprintf(cmdString, sizeof(cmdString), "setinfo \"%s\" \"%s\"\n", key, value); SendStringCommand(cmdString); } } @@ -2055,7 +2055,7 @@ void Server::ParseCenterPrint() char *string = m_Instream->ReadString(); if (m_ServerState == SERVER_CONNECTED) { - m_World->AddSignonData(svc_centerprint, (unsigned char *)string, strlen(string) + 1); + m_World->AddSignonData(svc_centerprint, (unsigned char *)string, Q_strlen(string) + 1); } else if (m_ServerState == SERVER_RUNNING || m_ServerState == SERVER_INTERMISSION) { @@ -2274,7 +2274,7 @@ void Server::Reset() m_ServerChannel.Close(); ClearFrame(true); - memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); + Q_memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); m_validSequence = 0; m_CurrentRetry = 0; @@ -2296,16 +2296,16 @@ char *Server::GetCmdName(int cmd) UserMsg *usermsg = m_World->GetUserMsg(cmd); if (usermsg) { - _snprintf(description, sizeof(description), "UserMsg:%s", usermsg->szName); + Q_snprintf(description, sizeof(description), "UserMsg:%s", usermsg->szName); } else { - _snprintf(description, sizeof(description), "Invalid UserMsg"); + Q_snprintf(description, sizeof(description), "Invalid UserMsg"); } } else { - _snprintf(description, sizeof(description), "EngMsg:%s", m_ClientFuncs[cmd].pszname); + Q_snprintf(description, sizeof(description), "EngMsg:%s", m_ClientFuncs[cmd].pszname); } return description; diff --git a/rehlds/HLTV/Core/src/World.cpp b/rehlds/HLTV/Core/src/World.cpp index 3cb4dbc..8fb764f 100644 --- a/rehlds/HLTV/Core/src/World.cpp +++ b/rehlds/HLTV/Core/src/World.cpp @@ -47,7 +47,7 @@ bool World::Init(IBaseSystem *system, int serial, char *name) m_SignonData.Resize(MAX_BUFFER_SIGNONDATA); m_ServerInfo.SetMaxSize(MAX_SERVERINFO_STRING); - memset(m_HostName, 0, sizeof(m_HostName)); + Q_memset(m_HostName, 0, sizeof(m_HostName)); Q_strlcpy(m_ServerName, "Unnamed HLTV"); m_Frames.Init(); @@ -61,7 +61,7 @@ bool World::Init(IBaseSystem *system, int serial, char *name) char *maxCacheparam = m_System->CheckParam("-cachesize"); if (maxCacheparam) { - m_MaxCacheIndex = atoi(maxCacheparam); + m_MaxCacheIndex = Q_atoi(maxCacheparam); } if (m_MaxCacheIndex <= 0) { @@ -134,7 +134,7 @@ void World::Reset() m_StartTime = 0; m_VoiceEnabled = false; - memset(m_ClientFallback, 0, sizeof(m_ClientFallback)); + Q_memset(m_ClientFallback, 0, sizeof(m_ClientFallback)); m_AllowCheats = false; m_IsHLTV = false; @@ -170,7 +170,7 @@ void World::ClearUserMessages() bool World::AddUserMessage(int msgNumber, int size, char *name) { UserMsg umsg; - memset(&umsg, 0, sizeof(umsg)); + Q_memset(&umsg, 0, sizeof(umsg)); umsg.iMsg = msgNumber; umsg.iSize = size; @@ -184,7 +184,7 @@ bool World::AddUserMessage(int msgNumber, int size, char *name) bool bFound = false; for (UserMsg *pList = m_ClientUserMsgs; pList; pList = pList->next) { - if (!_stricmp(pList->szName, umsg.szName)) { + if (!Q_stricmp(pList->szName, umsg.szName)) { bFound = true; pList->iMsg = umsg.iMsg; pList->iSize = umsg.iSize; @@ -194,7 +194,7 @@ bool World::AddUserMessage(int msgNumber, int size, char *name) if (!bFound) { UserMsg *pumsg = (UserMsg *)Mem_Malloc(sizeof(UserMsg)); - memcpy(pumsg, &umsg, sizeof(*pumsg)); + Q_memcpy(pumsg, &umsg, sizeof(*pumsg)); pumsg->next = m_ClientUserMsgs; m_ClientUserMsgs = pumsg; return true; @@ -218,7 +218,7 @@ void World::UpdatePlayer(int playerNum, int userId, char *infostring, char *hash player->active = true; player->userid = userId; - memcpy(player->hashedcdkey, hashedcdkey, sizeof(player->hashedcdkey)); + Q_memcpy(player->hashedcdkey, hashedcdkey, sizeof(player->hashedcdkey)); m_System->DPrintf("Player update(%i:%s)\n", playerNum, player->name); infostr.RemovePrefixedKeys('_'); @@ -227,10 +227,10 @@ void World::UpdatePlayer(int playerNum, int userId, char *infostring, char *hash Q_strlcpy(player->name, infostr.ValueForKey("name")); Q_strlcpy(player->model, infostr.ValueForKey("model")); - player->topcolor = atoi(infostr.ValueForKey("topcolor")); - player->bottomcolor = atoi(infostr.ValueForKey("bottomcolor")); - player->spectator = atoi(infostr.ValueForKey("*hltv")); - player->trackerID = atoi(infostr.ValueForKey("*fid")); + player->topcolor = Q_atoi(infostr.ValueForKey("topcolor")); + player->bottomcolor = Q_atoi(infostr.ValueForKey("bottomcolor")); + player->spectator = Q_atoi(infostr.ValueForKey("*hltv")); + player->trackerID = Q_atoi(infostr.ValueForKey("*fid")); BaseSystemModule::FireSignal(4, &playerNum); } @@ -242,7 +242,7 @@ bool World::AddResource(resource_t *resource) return false; } - memcpy(newresource, resource, sizeof(*newresource)); + Q_memcpy(newresource, resource, sizeof(*newresource)); newresource->data = nullptr; newresource->pNext = m_ResourcesList; @@ -284,7 +284,7 @@ void World::AddBaselineEntity(int index, entity_state_t *ent) return; } - memcpy(&m_BaseLines[index], ent, sizeof(m_BaseLines[index])); + Q_memcpy(&m_BaseLines[index], ent, sizeof(m_BaseLines[index])); } bool World::IsPlayerIndex(int index) @@ -298,7 +298,7 @@ bool World::IsPlayerIndex(int index) void World::ClearBaseline() { - memset(m_BaseLines, 0, sizeof(m_BaseLines)); + Q_memset(m_BaseLines, 0, sizeof(m_BaseLines)); for (auto& base : m_BaseLines) { base.entityType = ENTITY_UNINITIALIZED; @@ -307,7 +307,7 @@ void World::ClearBaseline() void World::ClearInstancedBaseline() { - memset(m_Instanced_BaseLines, 0, sizeof(m_Instanced_BaseLines)); + Q_memset(m_Instanced_BaseLines, 0, sizeof(m_Instanced_BaseLines)); } void World::AddInstancedBaselineEntity(int index, entity_state_t *ent) @@ -317,7 +317,7 @@ void World::AddInstancedBaselineEntity(int index, entity_state_t *ent) return; } - memcpy(&m_Instanced_BaseLines[index], ent, sizeof(m_Instanced_BaseLines[index])); + Q_memcpy(&m_Instanced_BaseLines[index], ent, sizeof(m_Instanced_BaseLines[index])); } void World::SetTime(double newTime) @@ -329,7 +329,7 @@ void World::SetTime(double newTime) void World::SetHostName(char *name) { if (!name || !name[0]) { - memset(m_HostName, 0, sizeof(m_HostName)); + Q_memset(m_HostName, 0, sizeof(m_HostName)); return; } @@ -338,7 +338,7 @@ void World::SetHostName(char *name) void World::ClearLightStyles() { - memset(m_Lightstyles, 0, sizeof(m_Lightstyles)); + Q_memset(m_Lightstyles, 0, sizeof(m_Lightstyles)); } void World::AddLightStyle(int index, char *style) @@ -348,7 +348,7 @@ void World::AddLightStyle(int index, char *style) return; } - int length = strlen(style); + int length = Q_strlen(style); if (length >= sizeof(m_Lightstyles[0])) { m_System->Printf("WARNING! World::SetLightStyle: style too long (%i).\n", length); } @@ -443,7 +443,7 @@ bool World::IsActive() void World::ClearPlayers() { - memset(m_Players, 0, sizeof(m_Players)); + Q_memset(m_Players, 0, sizeof(m_Players)); } void World::SetServerInfoString(char *infostring) @@ -464,7 +464,7 @@ void World::WriteBaseline(BitBuffer *stream) bool custom = false; int entnum = 0; entity_state_t nullstate; - memset(&nullstate, 0, sizeof(entity_state_t)); + Q_memset(&nullstate, 0, sizeof(entity_state_t)); for (auto& base : m_BaseLines) { @@ -515,7 +515,7 @@ char *World::GetHostName() void World::WriteServerinfo(BitBuffer *stream) { char message[2048]; - _snprintf(message, sizeof(message), "Protocol Version %i, Spawn count %i %s\n", m_Protocol, m_ServerCount, m_IsHLTV ? "(HLTV)" : ""); + Q_snprintf(message, sizeof(message), "Protocol Version %i, Spawn count %i %s\n", m_Protocol, m_ServerCount, m_IsHLTV ? "(HLTV)" : ""); stream->WriteByte(svc_print); stream->WriteString(message); @@ -564,7 +564,7 @@ void World::WriteDeltaDescriptions(BitBuffer *stream) int i, c; delta_description_t nulldesc; - memset(&nulldesc, 0, sizeof(nulldesc)); + Q_memset(&nulldesc, 0, sizeof(nulldesc)); for (auto p = m_Delta.GetRegistry(); p; p = p->next) { @@ -637,7 +637,7 @@ void World::WriteRegisteredUserMessages(BitBuffer *stream) void World::WriteResources(BitBuffer *stream) { unsigned char nullbuffer[32]; - memset(nullbuffer, 0, sizeof(nullbuffer)); + Q_memset(nullbuffer, 0, sizeof(nullbuffer)); if (g_DownloadURL[0]) { @@ -662,7 +662,7 @@ void World::WriteResources(BitBuffer *stream) stream->WriteBitData(resource->rgucMD5_hash, sizeof(resource->rgucMD5_hash)); } - if (!memcmp(resource->rguc_reserved, nullbuffer, sizeof(resource->rguc_reserved))) + if (!Q_memcmp(resource->rguc_reserved, nullbuffer, sizeof(resource->rguc_reserved))) { stream->WriteBit(0); } @@ -727,7 +727,7 @@ int World::AddFrame(frame_t *newFrame) m_Delta.SetLargeTimeBufferSize(true); BitBuffer tempStream(m_EntityBuffer, sizeof(m_EntityBuffer)); - memset(m_EntityBuffer, 0, sizeof(m_EntityBuffer)); + Q_memset(m_EntityBuffer, 0, sizeof(m_EntityBuffer)); compressedEntitiesSize = CompressFrame(newFrame, &tempStream); m_Delta.SetLargeTimeBufferSize(false); @@ -762,7 +762,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->entitiesSize) { - memcpy(pdata, m_EntityBuffer, compressedEntitiesSize); + Q_memcpy(pdata, m_EntityBuffer, compressedEntitiesSize); currentFrame->entities = pdata; currentFrame->entitiesSize = compressedEntitiesSize; currentFrame->entitynum = newFrame->entitynum; @@ -771,7 +771,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->clientDataSize) { - memcpy(pdata, newFrame->clientData, newFrame->clientDataSize); + Q_memcpy(pdata, newFrame->clientData, newFrame->clientDataSize); currentFrame->clientData = pdata; currentFrame->clientDataSize = newFrame->clientDataSize; pdata += currentFrame->clientDataSize; @@ -779,7 +779,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->eventsSize) { - memcpy(pdata, newFrame->events, newFrame->eventsSize); + Q_memcpy(pdata, newFrame->events, newFrame->eventsSize); currentFrame->events = pdata; currentFrame->eventsSize = newFrame->eventsSize; currentFrame->eventnum = newFrame->eventnum; @@ -788,7 +788,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->reliableDataSize) { - memcpy(pdata, newFrame->reliableData, newFrame->reliableDataSize); + Q_memcpy(pdata, newFrame->reliableData, newFrame->reliableDataSize); currentFrame->reliableData = pdata; currentFrame->reliableDataSize = newFrame->reliableDataSize; pdata += currentFrame->reliableDataSize; @@ -796,7 +796,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->unreliableDataSize) { - memcpy(pdata, newFrame->unreliableData, newFrame->unreliableDataSize); + Q_memcpy(pdata, newFrame->unreliableData, newFrame->unreliableDataSize); currentFrame->unreliableData = pdata; currentFrame->unreliableDataSize = newFrame->unreliableDataSize; pdata += currentFrame->unreliableDataSize; @@ -804,7 +804,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->voiceDataSize) { - memcpy(pdata, newFrame->voiceData, newFrame->voiceDataSize); + Q_memcpy(pdata, newFrame->voiceData, newFrame->voiceDataSize); currentFrame->voiceData = pdata; currentFrame->voiceDataSize = newFrame->voiceDataSize; pdata += currentFrame->voiceDataSize; @@ -812,7 +812,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->userMessagesSize) { - memcpy(pdata, newFrame->userMessages, newFrame->userMessagesSize); + Q_memcpy(pdata, newFrame->userMessages, newFrame->userMessagesSize); currentFrame->userMessages = pdata; currentFrame->userMessagesSize = newFrame->userMessagesSize; pdata += currentFrame->userMessagesSize; @@ -820,7 +820,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->demoDataSize) { - memcpy(pdata, newFrame->demoData, newFrame->demoDataSize); + Q_memcpy(pdata, newFrame->demoData, newFrame->demoDataSize); currentFrame->demoData = pdata; currentFrame->demoDataSize = newFrame->demoDataSize; pdata += currentFrame->demoDataSize; @@ -828,7 +828,7 @@ int World::AddFrame(frame_t *newFrame) if (newFrame->demoInfo) { - memcpy(pdata, newFrame->demoInfo, sizeof(demo_info_t)); + Q_memcpy(pdata, newFrame->demoInfo, sizeof(demo_info_t)); currentFrame->demoInfo = pdata; } @@ -892,7 +892,7 @@ void World::WriteFrame(frame_t *frame, unsigned int lastFrameSeqnr, BitBuffer *r if (GetClientData(frame, &clientData)) { clientdata_t nullClientData; - memset(&nullClientData, 0, sizeof(nullClientData)); + Q_memset(&nullClientData, 0, sizeof(nullClientData)); unreliableStream->WriteByte(svc_clientdata); unreliableStream->StartBitMode(); @@ -990,7 +990,7 @@ bool World::GetClientData(frame_t *frame, clientdata_t *clientData) } clientdata_t BaseLineClientData; - memset(&BaseLineClientData, 0, sizeof(BaseLineClientData)); + Q_memset(&BaseLineClientData, 0, sizeof(BaseLineClientData)); BitBuffer stream(frame->clientData, frame->clientDataSize); stream.StartBitMode(); @@ -1011,7 +1011,7 @@ bool World::GetUncompressedFrame(frame_t *deltaFrame, frame_t *frame) return false; } - memcpy(frame, deltaFrame, sizeof(*frame)); + Q_memcpy(frame, deltaFrame, sizeof(*frame)); frame->delta = 0; frame->entitiesSize = deltaFrame->entitynum * sizeof(entity_state_t); @@ -1039,10 +1039,10 @@ void World::ParseClientData(BitBuffer *stream, unsigned int deltaSeqNr, BitBuffe weapon_data_t nullWeaponData; clientdata_t fromClientData, nullClientData; - memset(&nullWeaponData, 0, sizeof(nullWeaponData)); - memset(&fromClientData, 0, sizeof(fromClientData)); - memset(&nullClientData, 0, sizeof(nullClientData)); - memset(clientData, 0, sizeof(*clientData)); + Q_memset(&nullWeaponData, 0, sizeof(nullWeaponData)); + Q_memset(&fromClientData, 0, sizeof(fromClientData)); + Q_memset(&nullClientData, 0, sizeof(nullClientData)); + Q_memset(clientData, 0, sizeof(*clientData)); if (deltaSeqNr && !GetClientData(deltaSeqNr, &fromClientData)) { m_System->Printf("WARNING! World::ParseClientData: couldn't uncompress delta frame %i\n", deltaSeqNr); @@ -1212,11 +1212,11 @@ void World::ClearEntityCache() m_DeltaCache[i].buffer.Free(); } - memset(m_DeltaCache, 0, sizeof(deltaCache_t) * m_MaxCacheIndex); + Q_memset(m_DeltaCache, 0, sizeof(deltaCache_t) * m_MaxCacheIndex); } if (m_FrameCache) { - memset(m_FrameCache, 0, sizeof(frameCache_t) * m_MaxCacheIndex); + Q_memset(m_FrameCache, 0, sizeof(frameCache_t) * m_MaxCacheIndex); } m_CacheHits = 1; @@ -1387,7 +1387,7 @@ char *World::GetStatusLine() static char string[256]; if (IsActive()) { - _snprintf(string, sizeof(string), + Q_snprintf(string, sizeof(string), "Game \"%s\", Map \"%s\", Time %s, Players %i\nFrame cache use %.1f, Buffered time %.0f .\n", m_GameDir, m_LevelName, @@ -1398,7 +1398,7 @@ char *World::GetStatusLine() } else { - _snprintf(string, sizeof(string), "World not active.\n"); + Q_snprintf(string, sizeof(string), "World not active.\n"); } return string; @@ -1408,7 +1408,7 @@ void World::ClearServerInfo() { m_ServerInfo.Clear(); - memset(&m_DetailedServerInfo, 0, sizeof(m_DetailedServerInfo)); + Q_memset(&m_DetailedServerInfo, 0, sizeof(m_DetailedServerInfo)); m_DetailedServerInfo.type = '?'; m_DetailedServerInfo.os = '?'; m_DetailedServerInfo.pw = '?'; @@ -1416,7 +1416,7 @@ void World::ClearServerInfo() void World::SetServerInfo(serverinfo_t *serverinfo) { - memcpy(&m_DetailedServerInfo, serverinfo, sizeof(m_DetailedServerInfo)); + Q_memcpy(&m_DetailedServerInfo, serverinfo, sizeof(m_DetailedServerInfo)); } void World::FinishGame() @@ -1453,7 +1453,7 @@ int World::FindUserMsgByName(char *name) { for (UserMsg *pList = m_ClientUserMsgs; pList; pList = pList->next) { - if (!strcmp(pList->szName, name)) { + if (!Q_strcmp(pList->szName, name)) { return pList->iMsg; } } @@ -1513,7 +1513,7 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi stream->m_Overflowed = true; } - memcpy(&entity[newindex], &deltaEntity[oldindex], sizeof(entity[newindex])); + Q_memcpy(&entity[newindex], &deltaEntity[oldindex], sizeof(entity[newindex])); newindex++; oldindex++; @@ -1592,7 +1592,7 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi stream->m_Overflowed = true; } - memcpy(&entity[newindex], &deltaEntity[oldindex], sizeof(entity[newindex])); + Q_memcpy(&entity[newindex], &deltaEntity[oldindex], sizeof(entity[newindex])); newindex++; oldindex++; } @@ -1638,14 +1638,14 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream) if (num >= MAX_ENTITIES) { m_System->Errorf("World::GetUncompressedFrame: entity number %i >= MAX_ENTITIES\n", num); - memset(frame, 0, sizeof(*frame)); + Q_memset(frame, 0, sizeof(*frame)); return false; } if (remove) { m_System->Errorf("World::GetUncompressedFrame: remove invalid on non-delta compressed frames\n"); - memset(frame, 0, sizeof(*frame)); + Q_memset(frame, 0, sizeof(*frame)); return false; } @@ -1849,7 +1849,7 @@ void World::SetServerInfo(int protocol, CRC32_t nserverCRC, unsigned char *nclie { m_Protocol = protocol; m_ServerCRC = nserverCRC; - memcpy(m_ClientdllMD5, nclientdllmd5, sizeof(m_ClientdllMD5)); + Q_memcpy(m_ClientdllMD5, nclientdllmd5, sizeof(m_ClientdllMD5)); m_Maxclients = nmaxclients; m_PlayerNum = nplayernum; @@ -1858,12 +1858,12 @@ void World::SetServerInfo(int protocol, CRC32_t nserverCRC, unsigned char *nclie Q_strlcpy(m_GameDir, ngamedir); Q_strlcpy(m_LevelName, nlevelname); - _snprintf(m_ServerName, sizeof(m_ServerName), "%s:%i", nservername, m_PlayerNum); + Q_snprintf(m_ServerName, sizeof(m_ServerName), "%s:%i", nservername, m_PlayerNum); } void World::SetMoveVars(movevars_t *nmovevars) { - memcpy(&m_MoveVars, nmovevars, sizeof(m_MoveVars)); + Q_memcpy(&m_MoveVars, nmovevars, sizeof(m_MoveVars)); } void World::SetPaused(bool state) @@ -1900,7 +1900,7 @@ void World::ParseDeltaDescription(BitBuffer *stream) { delta_description_t *pdesc; delta_description_t nulldesc; - memset(&nulldesc, 0, sizeof(nulldesc)); + Q_memset(&nulldesc, 0, sizeof(nulldesc)); char *s = stream->ReadString(); if (!s || !s[0]) { @@ -1974,7 +1974,7 @@ void World::SetExtraInfo(char *nclientfallback, int nallowCheats) void World::ParseEvent(BitBuffer *stream) { event_args_t nullargs; - memset(&nullargs, 0, sizeof(nullargs)); + Q_memset(&nullargs, 0, sizeof(nullargs)); m_Delta.ParseDelta(stream, (byte *)&nullargs, (byte *)&nullargs, GetEventDelta()); } @@ -1997,7 +1997,7 @@ void World::ParseBaseline(BitBuffer *stream) return; } - memset(&nullstate, 0, sizeof(nullstate)); + Q_memset(&nullstate, 0, sizeof(nullstate)); stream->StartBitMode(); m_MaxBaseLines = 0; ClearBaseline(); @@ -2005,9 +2005,9 @@ void World::ParseBaseline(BitBuffer *stream) while (stream->PeekBits(16) != 0xFFFF) { int index = stream->ReadBits(11); - m_MaxBaseLines = max(index, m_MaxBaseLines); + m_MaxBaseLines = Q_max(index, m_MaxBaseLines); - memset(&entstate, 0, sizeof(nullstate)); + Q_memset(&entstate, 0, sizeof(nullstate)); type = stream->ReadBits(2); custom = (type & ENTITY_BEAM) == ENTITY_BEAM; @@ -2036,7 +2036,7 @@ void World::ParseBaseline(BitBuffer *stream) m_MaxInstanced_BaseLine = stream->ReadBits(6); for (int i = 0; i < m_MaxInstanced_BaseLine; i++) { - memset(&entstate, 0, sizeof(entstate)); + Q_memset(&entstate, 0, sizeof(entstate)); m_Delta.ParseDelta(stream, (byte *)&nullstate, (byte *)&entstate, *ppentity); AddInstancedBaselineEntity(i, &entstate); } @@ -2113,7 +2113,7 @@ bool World::SaveAsDemo(char *filename, IDirector *director) unsigned int clientDelta = 0; unsigned int lastFrameSeqNr = 0; - memset(&cdata, 0, sizeof(cdata)); + Q_memset(&cdata, 0, sizeof(cdata)); frame_t *frame = (frame_t *)m_Frames.GetFirst(); if (!frame) { @@ -2237,7 +2237,7 @@ void World::RearrangeFrame(frame_t *frame, int seqNrOffset, float timeOffset) } BitBuffer tempStream(frame->entities, frame->entitiesSize); - memset(frame->entities, 0, frame->entitiesSize); + Q_memset(frame->entities, 0, frame->entitiesSize); int newsize = CompressFrame(&fullFrame, &tempStream); if ((unsigned)newsize > frame->entitiesSize || tempStream.IsOverflowed()) { diff --git a/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp b/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp index b194e5e..f4b7f8d 100644 --- a/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp +++ b/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp @@ -93,7 +93,7 @@ bool DemoPlayer::Init(IBaseSystem *system, int serial, char *name) m_IsSaving = false; m_MasterMode = true; - memset(m_DemoFileName, 0, sizeof(m_DemoFileName)); + Q_memset(m_DemoFileName, 0, sizeof(m_DemoFileName)); m_State = MODULE_RUNNING; m_System->DPrintf("DemoPlayer module initialized.\n"); @@ -263,7 +263,7 @@ void DemoPlayer::CMD_Jump(char *cmdLine) return; } - SetWorldTime(atof(params.GetToken(1)), true); + SetWorldTime(Q_atof(params.GetToken(1)), true); SetPaused(true); } @@ -276,7 +276,7 @@ void DemoPlayer::CMD_ForceHLTV(char *cmdLine) } char *val = params.GetToken(1); - ForceHLTV(atoi(val) ? true : false); + ForceHLTV(Q_atoi(val) ? true : false); } void DemoPlayer::CMD_Save(char *cmdLine) @@ -307,7 +307,7 @@ void DemoPlayer::CMD_Pause(char *cmdLine) } char *val = params.GetToken(1); - SetPaused(atoi(val) ? true : false); + SetPaused(Q_atoi(val) ? true : false); } void DemoPlayer::CMD_Speed(char *cmdLine) @@ -323,7 +323,7 @@ void DemoPlayer::CMD_Speed(char *cmdLine) return; } - float timescale = (float)atof(params.GetToken(1)); + float timescale = (float)Q_atof(params.GetToken(1)); SetTimeScale(timescale); } @@ -456,7 +456,7 @@ void DemoPlayer::SetWorldTime(double time, bool relative) void DemoPlayer::SetTimeScale(float scale) { - m_TimeScale = clamp(scale, 0.05f, 4.0f); + m_TimeScale = Q_clamp(scale, 0.05f, 4.0f); m_DemoStream.WriteByte(svc_timescale); m_DemoStream.WriteFloat(m_TimeScale); @@ -527,7 +527,7 @@ void DemoPlayer::GetDemoViewInfo(ref_params_t *rp, float *view, int *viewmodel) oldcmd = rp->cmd; demo_info_t *demoInfo = (demo_info_t *)frame->demoInfo; - memcpy(rp, &demoInfo->rp, sizeof(*rp)); + Q_memcpy(rp, &demoInfo->rp, sizeof(*rp)); rp->viewport[0] = oldviewport[0]; rp->viewport[1] = oldviewport[1]; @@ -734,7 +734,7 @@ int DemoPlayer::ReadDemoMessage(unsigned char *buffer, int size) return 0; } - memcpy(buffer, m_DemoStream.GetData(), msgsize); + Q_memcpy(buffer, m_DemoStream.GetData(), msgsize); m_DemoStream.FastClear(); return msgsize; } @@ -836,7 +836,7 @@ void DemoPlayer::ShutDown() char *DemoPlayer::FormatTime(float time) { static char timeCode[16]; - _snprintf(timeCode, sizeof(timeCode), "%02u:%02u:%02u", (int)time / 60, (int)time % 60, (int)(time * 100) % 100); + Q_snprintf(timeCode, sizeof(timeCode), "%02u:%02u:%02u", (int)time / 60, (int)time % 60, (int)(time * 100) % 100); return timeCode; } @@ -1009,7 +1009,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream) case DemoCmd::PayLoad: { unsigned char data[32768]; - memset(data, 0, sizeof(data)); + Q_memset(data, 0, sizeof(data)); int length = stream->ReadLong(); stream->ReadBuf(length, data); diff --git a/rehlds/HLTV/Director/src/Director.cpp b/rehlds/HLTV/Director/src/Director.cpp index 971eff1..eae4092 100644 --- a/rehlds/HLTV/Director/src/Director.cpp +++ b/rehlds/HLTV/Director/src/Director.cpp @@ -164,8 +164,8 @@ void Director::NewGame(IWorld *world, IProxy *proxy) m_World->RegisterListener(this); m_WorldModel = m_World->GetWorldModel(); - memset(m_history, 0, sizeof(*m_history) * m_historyLength); - memset(&m_frameEvent, 0, sizeof(m_frameEvent)); + Q_memset(m_history, 0, sizeof(*m_history) * m_historyLength); + Q_memset(&m_frameEvent, 0, sizeof(m_frameEvent)); ClearDirectorCommands(); @@ -193,7 +193,7 @@ void Director::AnalyseFrame(frame_t *frame) ranks[i] = now->players[i].rank; } - memset(now, 0, sizeof(*now)); + Q_memset(now, 0, sizeof(*now)); for (i = 0; i < MAX_CLIENTS; i++) { now->players[i].rank = ranks[i]; } @@ -215,7 +215,7 @@ void Director::AnalyseFrame(frame_t *frame) m_currentTime = frame->time; now->time = frame->time; - unsigned int count = min(maxclients, frame->entitynum); + unsigned int count = Q_min(maxclients, frame->entitynum); for (num = 0; num < count; num++) { entity_state_t *ent = &((entity_state_t *)frame->entities)[num]; @@ -246,7 +246,7 @@ void Director::AnalyseFrame(frame_t *frame) now->event.entity2 = m_frameEvent.entity2; now->event.flags = m_frameEvent.flags; - memset(&m_frameEvent, 0, sizeof(m_frameEvent)); + Q_memset(&m_frameEvent, 0, sizeof(m_frameEvent)); } void Director::SmoothRank(int playerNum, float rank) @@ -377,7 +377,7 @@ float Director::AddBestGenericCut() for (int i = 0; i < MAX_CLIENTS; i++) { - memset(sumTarget2Rank, 0, sizeof(sumTarget2Rank)); + Q_memset(sumTarget2Rank, 0, sizeof(sumTarget2Rank)); float tillTime = m_nextCutTime + 4; while (tillTime > m_history[seqNrMod].time) @@ -512,7 +512,7 @@ int Director::GetClosestPlayer(frame_t *frame, int entityIndex) m_WorldModel->SetPVS(origin); float minDistance = 32000.0f; - unsigned int count = min(maxclients, frame->entitynum); + unsigned int count = Q_min(maxclients, frame->entitynum); for (i = 0; i < count; i++) { @@ -679,8 +679,8 @@ void Director::CMD_SlowMotion(char *cmdLine) return; } - float val = (float)atof(params.GetToken(1)); - m_slowMotion = clamp(val, 0.05f, 4.0f); + float val = (float)Q_atof(params.GetToken(1)); + m_slowMotion = Q_clamp(val, 0.05f, 4.0f); } Director::worldHistory_t *Director::FindBestEvent() diff --git a/rehlds/HLTV/Proxy/src/DemoClient.cpp b/rehlds/HLTV/Proxy/src/DemoClient.cpp index 8ebc1fa..20e3657 100644 --- a/rehlds/HLTV/Proxy/src/DemoClient.cpp +++ b/rehlds/HLTV/Proxy/src/DemoClient.cpp @@ -37,7 +37,7 @@ DemoClient::DemoClient() m_LastFrameSeqNr = 0; m_IsActive = false; - memset(m_BaseFileName, 0, sizeof(m_BaseFileName)); + Q_memset(m_BaseFileName, 0, sizeof(m_BaseFileName)); } bool DemoClient::Init(IBaseSystem *system, int serial, char *name) @@ -49,7 +49,7 @@ bool DemoClient::Init(IBaseSystem *system, int serial, char *name) m_ClientDelta = 0; m_IsActive = false; - memset(m_BaseFileName, 0, sizeof(m_BaseFileName)); + Q_memset(m_BaseFileName, 0, sizeof(m_BaseFileName)); m_DemoInfo.SetMaxSize(MAX_DEMO_INFO); m_State = MODULE_RUNNING; @@ -61,7 +61,7 @@ bool DemoClient::Init(IBaseSystem *system, int serial, char *name) char *DemoClient::GetStatusLine() { static char string[256]; - _snprintf(string, sizeof(string), "Recording to %s (%.1f seconds)\n", m_DemoFile.GetFileName(), m_DemoFile.GetDemoTime()); + Q_snprintf(string, sizeof(string), "Recording to %s (%.1f seconds)\n", m_DemoFile.GetFileName(), m_DemoFile.GetDemoTime()); return string; } @@ -179,7 +179,7 @@ void DemoClient::WriteDatagram(double time, frame_t *frame) COM_FileBase(m_World->GetLevelName(), mapname); char fileName[MAX_PATH]; - _snprintf(fileName, sizeof(fileName), "%s-%s-%s.dem", m_BaseFileName, COM_TimeString(), mapname); + Q_snprintf(fileName, sizeof(fileName), "%s-%s-%s.dem", m_BaseFileName, COM_TimeString(), mapname); m_DemoFile.StartRecording(fileName); m_Proxy->WriteSignonData(TYPE_DEMO, &m_DemoChannel.m_reliableStream); @@ -208,7 +208,7 @@ void DemoClient::WriteDatagram(double time, frame_t *frame) m_DemoChannel.TransmitOutgoing(); client_data_t cdata; - memset(&cdata, 0, sizeof(cdata)); + Q_memset(&cdata, 0, sizeof(cdata)); m_DemoFile.WriteUpdateClientData(&cdata); } diff --git a/rehlds/HLTV/Proxy/src/FakeClient.cpp b/rehlds/HLTV/Proxy/src/FakeClient.cpp index d2be2af..b73d184 100644 --- a/rehlds/HLTV/Proxy/src/FakeClient.cpp +++ b/rehlds/HLTV/Proxy/src/FakeClient.cpp @@ -40,7 +40,7 @@ bool FakeClient::Init(IBaseSystem *system, int serial, char *name) { BaseSystemModule::Init(system, serial, name); - _snprintf(m_Name, sizeof(m_Name), "fakeclient%i", serial); + Q_snprintf(m_Name, sizeof(m_Name), "fakeclient%i", serial); m_Network = dynamic_cast(m_System->GetModule(NETWORK_INTERFACE_VERSION, "core")); if (!m_Network) @@ -56,7 +56,7 @@ bool FakeClient::Init(IBaseSystem *system, int serial, char *name) } char temp[256]; - sprintf(temp, "fakeserver%i", serial); + Q_sprintf(temp, "fakeserver%i", serial); m_Server = dynamic_cast(m_System->GetModule(SERVER_INTERFACE_VERSION, "core", temp)); if (!m_Server) @@ -72,7 +72,7 @@ bool FakeClient::Init(IBaseSystem *system, int serial, char *name) m_Server->SetPlayerName(m_Name); m_Server->SetAutoRetry(false); - sprintf(temp, "fakeworld%i", serial); + Q_sprintf(temp, "fakeworld%i", serial); m_World = dynamic_cast(m_System->GetModule(WORLD_INTERFACE_VERSION, "core", temp)); if (!m_World) @@ -121,7 +121,7 @@ void FakeClient::Say(char *text) return; char string[1024]; - _snprintf(string, sizeof(string), "say \"%s\"", text); + Q_snprintf(string, sizeof(string), "say \"%s\"", text); m_Server->SendStringCommand(text); } diff --git a/rehlds/HLTV/Proxy/src/Master.cpp b/rehlds/HLTV/Proxy/src/Master.cpp index a51496e..c3b628f 100644 --- a/rehlds/HLTV/Proxy/src/Master.cpp +++ b/rehlds/HLTV/Proxy/src/Master.cpp @@ -58,7 +58,7 @@ Master::Master() int Master::GetGameAppID(const char *gamedir) const { for (auto& game : m_GameToAppIDMap) { - if (!_stricmp(game.dir, gamedir)) { + if (!Q_stricmp(game.dir, gamedir)) { return game.appID; } } @@ -168,7 +168,7 @@ void Master::RunFrame(double time) int slots, proxies, spectators; m_Proxy->GetStatistics(proxies, slots, spectators); - SteamGameServer()->SetMaxPlayerCount(min(slots, 127)); // max slots + SteamGameServer()->SetMaxPlayerCount(Q_min(slots, 127)); // max slots SteamGameServer()->SetServerName(szHostName); SteamGameServer()->SetMapName(mapName); SteamGameServer()->SetPasswordProtected(m_Proxy->IsPasswordProtected()); @@ -240,7 +240,7 @@ void Master::CMD_NoMaster(char *cmdLine) } bool bOldMasterState = m_NoMaster; - m_NoMaster = atoi(params.GetToken(1)) ? true : false; + m_NoMaster = Q_atoi(params.GetToken(1)) ? true : false; if (bOldMasterState != m_NoMaster) { SteamGameServer()->EnableHeartbeats(m_NoMaster); @@ -294,6 +294,6 @@ void Master::SendShutdown() char *Master::GetStatusLine() { static char string[256]; - _snprintf(string, sizeof(string), "Master servers: 0\n"); + Q_snprintf(string, sizeof(string), "Master servers: 0\n"); return string; } diff --git a/rehlds/HLTV/Proxy/src/Proxy.cpp b/rehlds/HLTV/Proxy/src/Proxy.cpp index fd8b3f9..c49f635 100644 --- a/rehlds/HLTV/Proxy/src/Proxy.cpp +++ b/rehlds/HLTV/Proxy/src/Proxy.cpp @@ -110,7 +110,7 @@ bool Proxy::Init(IBaseSystem *system, int serial, char *name) } char *portparam = m_System->CheckParam("-port"); - int proxyport = atoi(portparam ? portparam : PROXY_DEFAULT_PORT); + int proxyport = Q_atoi(portparam ? portparam : PROXY_DEFAULT_PORT); if (!(m_Socket = (INetSocket *)m_Network->CreateSocket(proxyport))) { @@ -201,20 +201,20 @@ bool Proxy::Init(IBaseSystem *system, int serial, char *name) m_RconAddress.Clear(); // Clear buffers - memset(m_RconPassword, 0, sizeof(m_RconPassword)); - memset(m_AdminPassword, 0, sizeof(m_AdminPassword)); - memset(m_ProxyPassword, 0, sizeof(m_ProxyPassword)); - memset(m_SpectatorPassword, 0, sizeof(m_SpectatorPassword)); - memset(m_LastRconCommand, 0, sizeof(m_LastRconCommand)); - memset(m_OffLineText, 0, sizeof(m_OffLineText)); - memset(m_SignonCommands, 0, sizeof(m_SignonCommands)); - memset(m_Challenges, 0, sizeof(m_Challenges)); + Q_memset(m_RconPassword, 0, sizeof(m_RconPassword)); + Q_memset(m_AdminPassword, 0, sizeof(m_AdminPassword)); + Q_memset(m_ProxyPassword, 0, sizeof(m_ProxyPassword)); + Q_memset(m_SpectatorPassword, 0, sizeof(m_SpectatorPassword)); + Q_memset(m_LastRconCommand, 0, sizeof(m_LastRconCommand)); + Q_memset(m_OffLineText, 0, sizeof(m_OffLineText)); + Q_memset(m_SignonCommands, 0, sizeof(m_SignonCommands)); + Q_memset(m_Challenges, 0, sizeof(m_Challenges)); m_LoopCommands.Init(); m_BannList.Init(); m_Resources.Init(); - memset(&m_LocalMessage, 0, sizeof(m_LocalMessage)); + Q_memset(&m_LocalMessage, 0, sizeof(m_LocalMessage)); m_LocalMessage = { 0, // effect 255, 160, 0, 255, // r1, g1, b1, a1 @@ -225,7 +225,7 @@ bool Proxy::Init(IBaseSystem *system, int serial, char *name) "" // text }; - memset(&m_CommentatorMessage, 0, sizeof(m_CommentatorMessage)); + Q_memset(&m_CommentatorMessage, 0, sizeof(m_CommentatorMessage)); m_CommentatorMessage = { 0, // effect 255, 160, 0, 255, // r1, g1, b1, a1 @@ -390,7 +390,7 @@ void Proxy::CMD_Ping(char *cmdLine) } if (!to.m_Port) { - to.SetPort(atoi("27015")); + to.SetPort(Q_atoi("27015")); } m_Socket->OutOfBandPrintf(&to, "ping"); @@ -444,7 +444,7 @@ void Proxy::ReplyConnect(NetAddress *to, int protocol, int challenge, char *prot InfoString info(userinfo); NetAddress relayProxy; - int type = atoi(info.ValueForKey("*hltv")); + int type = Q_atoi(info.ValueForKey("*hltv")); char *name = info.ValueForKey("name"); if (protocol != PROTOCOL_VERSION) { @@ -568,7 +568,7 @@ void Proxy::RejectConnection(NetAddress *adr, bool badPassword, const char *fmt, char text[1024] = ""; va_start(argptr, fmt); - _vsnprintf(text, sizeof(text), fmt, argptr); + Q_vsnprintf(text, sizeof(text), fmt, argptr); va_end(argptr); if (badPassword) { @@ -584,7 +584,7 @@ void Proxy::RejectConnection(NetAddress *adr, bool badPassword, const char *fmt, char *Proxy::GetStatusLine() { static char string[256]; - _snprintf(string, sizeof(string), "Proxy name \"%s\", %s, Port %i, Clients %i/%i.\n", m_World->GetName(), m_IsMaster ? "Master" : "Relay", m_Socket->GetPort(), m_Clients.CountElements(), m_MaxClients); + Q_snprintf(string, sizeof(string), "Proxy name \"%s\", %s, Port %i, Clients %i/%i.\n", m_World->GetName(), m_IsMaster ? "Master" : "Relay", m_Socket->GetPort(), m_Clients.CountElements(), m_MaxClients); return string; } @@ -629,7 +629,7 @@ void Proxy::UpdateStatusLine() m_Network->GetFlowStats(&in, &out); m_CurrentLoss = m_Server->GetPacketLoss(); - _snprintf(text, sizeof(text), "%s, Time %s, Delay %.0f, FPS %.0f, Clients %i, In %.1f, Out %.1f, Loss %.2f", + Q_snprintf(text, sizeof(text), "%s, Time %s, Delay %.0f, FPS %.0f, Clients %i, In %.1f, Out %.1f, Loss %.2f", IsMaster() ? "Master" : "Relay", activeTime, m_ClientDelay, m_FPS, m_Clients.CountElements(), in, out, m_CurrentLoss); m_System->SetStatusLine(text); @@ -865,7 +865,7 @@ void Proxy::CMD_Say(char *cmdLine) if (m_Server->IsConnected()) { char string[1024]; - _snprintf(string, sizeof(string), "say \"%s\"", params.GetRestOfLine(1)); + Q_snprintf(string, sizeof(string), "say \"%s\"", params.GetRestOfLine(1)); m_Server->SendStringCommand(string); } } @@ -880,7 +880,7 @@ void Proxy::CMD_MaxClients(char *cmdLine) return; } - if (!SetMaxClients(atoi(params.GetToken(1)))) { + if (!SetMaxClients(Q_atoi(params.GetToken(1)))) { m_System->Printf("Allowed maximum number of local clients is %i.\n", MAX_PROXY_CLIENTS); return; } @@ -904,7 +904,7 @@ bool Proxy::SetMaxClients(int number) void Proxy::SetMaxLoss(float maxloss) { - m_MaxLoss = clamp(maxloss, 0.0f, 1.0f); + m_MaxLoss = Q_clamp(maxloss, 0.0f, 1.0f); } int Proxy::GetMaxClients() @@ -927,7 +927,7 @@ void Proxy::CMD_Delay(char *cmdLine) return; } - SetDelay(float(atof(params.GetToken(1)))); + SetDelay(float(Q_atof(params.GetToken(1)))); } void Proxy::CMD_Stop(char *cmdLine) @@ -947,7 +947,7 @@ void Proxy::CMD_Connect(char *cmdLine) } if (!address.m_Port) { - address.SetPort(atoi("27015")); + address.SetPort(Q_atoi("27015")); } Reset(); @@ -964,7 +964,7 @@ void Proxy::CMD_Name(char *cmdLine) } char name[MAX_NAME]; - int len = strlen(params.GetToken(1)); + int len = Q_strlen(params.GetToken(1)); if (len > sizeof(name) - 1) { m_System->Printf("Invalid name length.\n"); return; @@ -987,9 +987,9 @@ void Proxy::CMD_Msg(char *cmdLine) if (params.CountToken() == 6) { - m_LocalMessage.holdtime = float(atof(params.GetToken(2))); - m_LocalMessage.x = float(atof(params.GetToken(3))); - m_LocalMessage.y = float(atof(params.GetToken(4))); + m_LocalMessage.holdtime = float(Q_atof(params.GetToken(2))); + m_LocalMessage.x = float(Q_atof(params.GetToken(3))); + m_LocalMessage.y = float(Q_atof(params.GetToken(4))); sscanf(params.GetToken(5), "%2hhx%2hhx%2hhx%2hhx", &m_LocalMessage.r1, &m_LocalMessage.g1, &m_LocalMessage.b1, &m_LocalMessage.a1); } @@ -1010,7 +1010,7 @@ void Proxy::CMD_Protocol(char *cmdLine) return; } - if (!m_Server->SetProtocol(atoi(params.GetToken(1)))) { + if (!m_Server->SetProtocol(Q_atoi(params.GetToken(1)))) { m_System->Printf("Protocol version not supported!\n"); return; } @@ -1026,7 +1026,7 @@ void Proxy::CMD_MaxRate(char *cmdLine) return; } - SetMaxRate(atoi(params.GetToken(1))); + SetMaxRate(Q_atoi(params.GetToken(1))); } void Proxy::CMD_ServerCmd(char *cmdLine) @@ -1053,9 +1053,9 @@ void Proxy::CMD_ClientCmd(char *cmdLine) return; } - int group = atoi(params.GetToken(1)); + int group = Q_atoi(params.GetToken(1)); char *cmdstring = params.GetRestOfLine(2); - if (strlen(cmdstring) > 100) { + if (Q_strlen(cmdstring) > 100) { m_System->Printf("ERROR! Command string too long.\n"); return; } @@ -1090,7 +1090,7 @@ void Proxy::CMD_Rate(char *cmdLine) return; } - m_Server->SetRate(atoi(params.GetToken(1))); + m_Server->SetRate(Q_atoi(params.GetToken(1))); } void Proxy::CMD_Players(char *cmdLine) @@ -1117,7 +1117,7 @@ void Proxy::CMD_HostName(char *cmdLine) return; } - if (!_stricmp(params.GetToken(1), "none")) { + if (!Q_stricmp(params.GetToken(1), "none")) { m_World->SetHostName(nullptr); return; } @@ -1135,7 +1135,7 @@ void Proxy::CMD_Updaterate(char *cmdLine) return; } - SetMaxUpdateRate(atoi(params.GetToken(1))); + SetMaxUpdateRate(Q_atoi(params.GetToken(1))); m_Server->SetUpdateRate(m_MaxUpdateRate); } @@ -1149,7 +1149,7 @@ void Proxy::CMD_BlockVoice(char *cmdLine) return; } - m_Server->SetVoiceBlocking(atoi(params.GetToken(1)) ? true : false); + m_Server->SetVoiceBlocking(Q_atoi(params.GetToken(1)) ? true : false); } void Proxy::CMD_Record(char *cmdLine) @@ -1187,8 +1187,8 @@ void Proxy::CMD_LoopCmd(char *cmdLine) return; } - int id = atoi(params.GetToken(1)); - float seconds = float(atof(params.GetToken(2))); + int id = Q_atoi(params.GetToken(1)); + float seconds = float(Q_atof(params.GetToken(2))); char *cmds = params.GetRestOfLine(3); loopcmd_t *lcmd = (loopcmd_t *)m_LoopCommands.GetFirst(); @@ -1201,7 +1201,7 @@ void Proxy::CMD_LoopCmd(char *cmdLine) lcmd = (loopcmd_t *)m_LoopCommands.GetNext(); } - if (!_stricmp(cmds, "none") || !seconds) + if (!Q_stricmp(cmds, "none") || !seconds) { if (lcmd) { m_LoopCommands.Remove(lcmd); @@ -1238,7 +1238,7 @@ void Proxy::CMD_RconAddress(char *cmdLine) m_Network->ResolveAddress(params.GetToken(1), &m_RconAddress); if (!m_RconAddress.m_Port) { - m_RconAddress.SetPort(atoi("27015")); + m_RconAddress.SetPort(Q_atoi("27015")); } } @@ -1367,7 +1367,7 @@ void Proxy::CMD_ProxyPassword(char *cmdLine) return; } - if (!_stricmp(params.GetToken(1), "none")) { + if (!Q_stricmp(params.GetToken(1), "none")) { m_ProxyPassword[0] = '\0'; return; } @@ -1512,9 +1512,9 @@ bool Proxy::ProcessConnectionlessMessage(NetAddress *from, BitBuffer *stream) { const int maxBuffer = 4096; unsigned char data[maxBuffer]; - int maxSize = min(stream->m_MaxSize, maxBuffer); + int maxSize = Q_min(stream->m_MaxSize, maxBuffer); - memcpy((char *)&data[4], stream->m_Data, maxSize); + Q_memcpy((char *)&data[4], stream->m_Data, maxSize); *(uint32 *)data = CONNECTIONLESS_HEADER; // connectionless packet SteamGameServer()->HandleIncomingPacket(data, maxSize + 4, ntohl(*(u_long *)&from->m_IP[0]), htons(from->m_Port)); @@ -1527,14 +1527,14 @@ bool Proxy::ProcessConnectionlessMessage(NetAddress *from, BitBuffer *stream) return false; } - if (!strcmp(c, "challenge")) + if (!Q_strcmp(c, "challenge")) { char *type = cmdLine.GetToken(1); switch (cmdLine.CountToken()) { case 3: { - if (type && type[0] && !_stricmp(type, "rcon")) + if (type && type[0] && !Q_stricmp(type, "rcon")) { unsigned int challengeNr = strtoul(cmdLine.GetToken(2), 0, 10); SendRcon(from, challengeNr); @@ -1552,7 +1552,7 @@ bool Proxy::ProcessConnectionlessMessage(NetAddress *from, BitBuffer *stream) return false; } } - else if (!strcmp(c, "rcon")) + else if (!Q_strcmp(c, "rcon")) { if (cmdLine.CountToken() < 4) { return false; @@ -1568,7 +1568,7 @@ bool Proxy::ProcessConnectionlessMessage(NetAddress *from, BitBuffer *stream) return false; } - if (!m_AdminPassword[0] || strcmp(m_AdminPassword, password) != 0) + if (!m_AdminPassword[0] || Q_strcmp(m_AdminPassword, password) != 0) { m_System->Printf("Invalid rcon password from: %s\n", from->ToString()); return false; @@ -1576,16 +1576,16 @@ bool Proxy::ProcessConnectionlessMessage(NetAddress *from, BitBuffer *stream) ExecuteRcon(from, command); } - else if (!strcmp(c, "getchallenge")) + else if (!Q_strcmp(c, "getchallenge")) { ReplyChallenge(from); } - else if (!strcmp(c, "connect")) + else if (!Q_strcmp(c, "connect")) { if (cmdLine.CountToken() == 5) { - int protocol = atoi(cmdLine.GetToken(1)); - int challenge = atoi(cmdLine.GetToken(2)); + int protocol = Q_atoi(cmdLine.GetToken(1)); + int challenge = Q_atoi(cmdLine.GetToken(2)); char *protinfo = cmdLine.GetToken(3); char *userinfo = cmdLine.GetToken(4); @@ -1613,38 +1613,38 @@ bool Proxy::ProcessConnectionlessMessage(NetAddress *from, BitBuffer *stream) { ReplyRules(from); } - else if (!strcmp(c, "listen")) + else if (!Q_strcmp(c, "listen")) { ReplyListen(from); } // guard to frequency queries else if (m_MaxFrameQueries > 0) { - if (!strcmp(c, "ping") || (c[0] == A2A_PING && (c[1] == 0 || c[1] == '\n'))) + if (!Q_strcmp(c, "ping") || (c[0] == A2A_PING && (c[1] == 0 || c[1] == '\n'))) { ReplyPing(from); } - else if (!_stricmp(c, "infostring")) + else if (!Q_stricmp(c, "infostring")) { ReplyInfoString(from); } - else if (!_stricmp(c, "info")) + else if (!Q_stricmp(c, "info")) { ReplyInfo(from, false); } - else if (!_stricmp(c, "details")) + else if (!Q_stricmp(c, "details")) { ReplyInfo(from, true); } - else if (!_stricmp(c, "players")) + else if (!Q_stricmp(c, "players")) { ReplyPlayers(from); } - else if (!_stricmp(c, "rules")) + else if (!Q_stricmp(c, "rules")) { ReplyRules(from); } - else if (!_stricmp(c, "log")) + else if (!Q_stricmp(c, "log")) { m_System->Printf("Ignoring log from %s.\n", from->ToString()); return false; @@ -1680,7 +1680,7 @@ void Proxy::CMD_ChatMode(char *cmdLine) return; } - m_ChatMode = clamp((ChatMode_e)atoi(params.GetToken(1)), CHAT_OFF, CHAT_GLOBAL); + m_ChatMode = Q_clamp((ChatMode_e)Q_atoi(params.GetToken(1)), CHAT_OFF, CHAT_GLOBAL); } void Proxy::CMD_MaxQueries(char *cmdLine) @@ -1693,7 +1693,7 @@ void Proxy::CMD_MaxQueries(char *cmdLine) return; } - m_MaxQueries = float(atof(params.GetToken(1))); + m_MaxQueries = float(Q_atof(params.GetToken(1))); } void Proxy::CMD_Kick(char *cmdLine) @@ -1705,7 +1705,7 @@ void Proxy::CMD_Kick(char *cmdLine) return; } - int id = atoi(params.GetToken(1)); + int id = Q_atoi(params.GetToken(1)); IClient *client = (IClient *)m_Clients.GetFirst(); while (client) @@ -1742,7 +1742,7 @@ void Proxy::ChatSpectator(char *nick, char *text) // TODO: too harsh, let more? maxlen: 190 const int maxLengthOfString = 64; - int len = strlen(text); + int len = Q_strlen(text); if (len <= 0) { return; } @@ -1753,7 +1753,7 @@ void Proxy::ChatSpectator(char *nick, char *text) if (m_ChatMode != CHAT_LOCAL && !m_IsMaster) { - _snprintf(string, sizeof(string), "say \"%s\"", text); + Q_snprintf(string, sizeof(string), "say \"%s\"", text); if (m_Server->IsConnected()) { m_Server->SendStringCommand(string); } @@ -1765,9 +1765,9 @@ void Proxy::ChatSpectator(char *nick, char *text) const int headerBytes = 3; // reserve a header of 3 bytes. const int maxSizeOfMessage = MAX_USER_MSG_DATA - headerBytes; // user message size limit is 192 bytes - _snprintf(&string[ headerBytes ], sizeof(string) - headerBytes, "<%s> %s", nick, text); + Q_snprintf(&string[ headerBytes ], sizeof(string) - headerBytes, "<%s> %s", nick, text); - int curLen = strlen(&string[ headerBytes ]); + int curLen = Q_strlen(&string[ headerBytes ]); if (curLen > maxSizeOfMessage) { curLen = maxSizeOfMessage; } @@ -1798,11 +1798,11 @@ bool Proxy::IsMaster() bool Proxy::CheckDirectorModule() { char szAbsoluteLibFilename[MAX_PATH]; - if (m_Director && !strcmp(m_Director->GetModName(), m_World->GetGameDir())) { + if (m_Director && !Q_strcmp(m_Director->GetModName(), m_World->GetGameDir())) { return true; } - _snprintf(szAbsoluteLibFilename, sizeof(szAbsoluteLibFilename), "%s/dlls/director", m_World->GetGameDir()); + Q_snprintf(szAbsoluteLibFilename, sizeof(szAbsoluteLibFilename), "%s/dlls/director", m_World->GetGameDir()); if (m_Director) { m_System->RemoveModule(m_Director); } @@ -1874,7 +1874,7 @@ void Proxy::CMD_AddResource(char *cmdLine) return; } - if (!AddResource(params.GetToken(1), (resourcetype_t)atoi(params.GetToken(2)), params.GetToken(3))) + if (!AddResource(params.GetToken(1), (resourcetype_t)Q_atoi(params.GetToken(2)), params.GetToken(3))) { m_System->Printf("Error! Failed to load resource %s.\n", params.GetToken(1)); return; @@ -1891,7 +1891,7 @@ void Proxy::CMD_PublicGame(char *cmdLine) return; } - m_PublicGame = atoi(params.GetToken(1)) ? true : false; + m_PublicGame = Q_atoi(params.GetToken(1)) ? true : false; } void Proxy::WriteHUDMsg(textmessage_t *msg, BitBuffer *stream) @@ -1926,7 +1926,7 @@ void Proxy::CMD_SpectatorPassword(char *cmdLine) return; } - if (!_stricmp(params.GetToken(1), "none")) { + if (!Q_stricmp(params.GetToken(1), "none")) { m_SpectatorPassword[0] = '\0'; return; } @@ -1946,7 +1946,7 @@ void Proxy::CMD_DispatchMode(char *cmdLine) return; } - m_DispatchMode = clamp((DispatchMode_e)atoi(params.GetToken(1)), DISPATCH_OFF, DISPATCH_ALL); + m_DispatchMode = Q_clamp((DispatchMode_e)Q_atoi(params.GetToken(1)), DISPATCH_OFF, DISPATCH_ALL); } bool Proxy::IsValidPassword(int type, char *pw) @@ -1957,7 +1957,7 @@ bool Proxy::IsValidPassword(int type, char *pw) case TYPE_CLIENT: { if (m_SpectatorPassword[0]) { - return strcmp(m_SpectatorPassword, pw) == 0; + return Q_strcmp(m_SpectatorPassword, pw) == 0; } return true; @@ -1966,7 +1966,7 @@ bool Proxy::IsValidPassword(int type, char *pw) case TYPE_PROXY: { if (m_ProxyPassword[0]) { - return strcmp(m_ProxyPassword, pw) == 0; + return Q_strcmp(m_ProxyPassword, pw) == 0; } // password is not set @@ -1976,7 +1976,7 @@ bool Proxy::IsValidPassword(int type, char *pw) case TYPE_COMMENTATOR: { if (m_AdminPassword[0]) { - return strcmp(m_AdminPassword, pw) == 0; + return Q_strcmp(m_AdminPassword, pw) == 0; } break; @@ -2099,7 +2099,7 @@ void Proxy::CMD_SignOnCommands(char *cmdLine) return; } - if (strlen(params.GetToken(1)) > 250) + if (Q_strlen(params.GetToken(1)) > 250) { m_System->Printf("Error! String too long (>250)!\n"); return; @@ -2117,7 +2117,7 @@ void Proxy::CMD_AdminPassword(char *cmdLine) return; } - if (!_stricmp(params.GetToken(1), "none")) { + if (!Q_stricmp(params.GetToken(1), "none")) { m_AdminPassword[0] = '\0'; return; } @@ -2138,9 +2138,9 @@ void Proxy::CMD_LocalMsg(char *cmdLine) if (params.CountToken() == 6) { - m_LocalMessage.holdtime = float(atof(params.GetToken(2))); - m_LocalMessage.x = float(atof(params.GetToken(3))); - m_LocalMessage.y = float(atof(params.GetToken(4))); + m_LocalMessage.holdtime = float(Q_atof(params.GetToken(2))); + m_LocalMessage.x = float(Q_atof(params.GetToken(3))); + m_LocalMessage.y = float(Q_atof(params.GetToken(4))); sscanf(params.GetToken(5), "%2hhx%2hhx%2hhx%2hhx", &m_LocalMessage.r1, &m_LocalMessage.g1, &m_LocalMessage.b1, &m_LocalMessage.a1); } @@ -2187,13 +2187,13 @@ void Proxy::CMD_AddFakeClients(char *cmdLine) return; } - int number = atoi(params.GetToken(1)); + int number = Q_atoi(params.GetToken(1)); NetAddress adr; m_Network->ResolveAddress(params.GetToken(2), &adr); - int rate = atoi(params.GetToken(3)); - float activity = float(atof(params.GetToken(4))); + int rate = Q_atoi(params.GetToken(3)); + float activity = float(Q_atof(params.GetToken(4))); for (int i = 0; i < number; i++) { @@ -2219,7 +2219,7 @@ void Proxy::CMD_MaxLoss(char *cmdLine) return; } - SetMaxLoss(float(atof(params.GetToken(1)))); + SetMaxLoss(float(Q_atof(params.GetToken(1)))); } void Proxy::CMD_Region(char *cmdLine) @@ -2232,7 +2232,7 @@ void Proxy::CMD_Region(char *cmdLine) return; } - SetRegion(atoi(params.GetToken(1))); + SetRegion(Q_atoi(params.GetToken(1))); } void Proxy::CMD_Bann(char *cmdLine) @@ -2296,7 +2296,7 @@ void Proxy::CMD_AutoRetry(char *cmdLine) return; } - m_Server->SetAutoRetry(atoi(params.GetToken(1)) ? true : false); + m_Server->SetAutoRetry(Q_atoi(params.GetToken(1)) ? true : false); } void Proxy::CMD_BannerFile(char *cmdLine) @@ -2314,7 +2314,7 @@ void Proxy::CMD_BannerFile(char *cmdLine) return; } - if (!_stricmp(params.GetToken(1), "none")) { + if (!Q_stricmp(params.GetToken(1), "none")) { m_BannerTGA = nullptr; return; } @@ -2324,7 +2324,7 @@ void Proxy::CMD_BannerFile(char *cmdLine) return; } - _snprintf(m_BannerTGA->szFileName, sizeof(m_BannerTGA->szFileName), "gfx/temp/%s.tga", COM_BinPrintf(m_BannerTGA->rgucMD5_hash, sizeof(m_BannerTGA->rgucMD5_hash))); + Q_snprintf(m_BannerTGA->szFileName, sizeof(m_BannerTGA->szFileName), "gfx/temp/%s.tga", COM_BinPrintf(m_BannerTGA->rgucMD5_hash, sizeof(m_BannerTGA->rgucMD5_hash))); } void Proxy::CMD_CheeringThreshold(char *cmdLine) @@ -2337,7 +2337,7 @@ void Proxy::CMD_CheeringThreshold(char *cmdLine) return; } - m_CheeringThreshold = float(atof(params.GetToken(1))); + m_CheeringThreshold = float(Q_atof(params.GetToken(1))); } float Proxy::GetDelay() @@ -2407,7 +2407,7 @@ void Proxy::CreateServerInfoString(InfoString *info) m_Status.GetLocalStats(proxies, slots, spectators); char address[256]; - _snprintf(address, sizeof(address), "%s", m_Network->GetLocalAddress()->ToString()); + Q_snprintf(address, sizeof(address), "%s", m_Network->GetLocalAddress()->ToString()); info->SetValueForKey("protocol", COM_VarArgs("%i", PROTOCOL_VERSION)); info->SetValueForKey("address", address); @@ -2455,13 +2455,13 @@ void Proxy::CreateServerInfoString(InfoString *info) void Proxy::SetMaxRate(int rate) { // maxrate: 1.000 - 20.000 - m_MaxRate = clamp(rate, 1000, MAX_PROXY_RATE); + m_MaxRate = Q_clamp(rate, 1000, MAX_PROXY_RATE); } void Proxy::SetMaxUpdateRate(int updaterate) { // maxupdaterate: 1.0 - 40.0 - m_MaxUpdateRate = clamp(updaterate, 1, MAX_PROXY_UPDATERATE); + m_MaxUpdateRate = Q_clamp(updaterate, 1, MAX_PROXY_UPDATERATE); } void Proxy::SetDelay(float seconds) @@ -2495,7 +2495,7 @@ void Proxy::SetClientTime(double time, bool relative) void Proxy::SetClientTimeScale(float scale) { BitBuffer buf(32); - m_ClientTimeScale = clamp(scale, 0.5f, 4.0f); + m_ClientTimeScale = Q_clamp(scale, 0.5f, 4.0f); buf.WriteByte(svc_timescale); buf.WriteFloat(m_ClientTimeScale); @@ -2564,7 +2564,7 @@ void Proxy::NewGameStarted() m_Server->SetDirector(m_Director); char newTitle[4096]; - _snprintf(newTitle, sizeof(newTitle), "HLTV - %s %s", + Q_snprintf(newTitle, sizeof(newTitle), "HLTV - %s %s", m_Server->IsDemoFile() ? m_Server->GetDemoFileName() : m_Server->GetAddress()->ToString(), m_World->GetLevelName()); @@ -2626,7 +2626,7 @@ void Proxy::UpdateInfoMessages() serverinfo_t *serverInfo = m_World->GetServerInfo(); m_Status.GetLocalStats(proxies, slots, spectators); - _snprintf(ipport, sizeof(ipport), "%s:%i", m_Network->GetLocalAddress()->ToBaseString(), m_Socket->GetPort()); + Q_snprintf(ipport, sizeof(ipport), "%s:%i", m_Network->GetLocalAddress()->ToBaseString(), m_Socket->GetPort()); m_InfoInfo.Clear(); if (m_World->IsActive()) @@ -2639,8 +2639,8 @@ void Proxy::UpdateInfoMessages() m_InfoInfo.WriteString(serverInfo->map); // mapname m_InfoInfo.WriteString(serverInfo->gamedir); // gamedir m_InfoInfo.WriteString(serverInfo->description); // gamename - m_InfoInfo.WriteByte(min(spectators, MAX_PROXY_CLIENTS)); // players - m_InfoInfo.WriteByte(min(slots, MAX_PROXY_CLIENTS)); // maxplayers + m_InfoInfo.WriteByte(Q_min(spectators, MAX_PROXY_CLIENTS)); // players + m_InfoInfo.WriteByte(Q_min(slots, MAX_PROXY_CLIENTS)); // maxplayers m_InfoInfo.WriteByte(PROTOCOL_VERSION); // protocol if (spectators >= MAX_PROXY_CLIENTS || slots >= MAX_PROXY_CLIENTS) @@ -2660,8 +2660,8 @@ void Proxy::UpdateInfoMessages() m_InfoDetails.WriteString(serverInfo->map); // mapname m_InfoDetails.WriteString(serverInfo->gamedir); // gamedir m_InfoDetails.WriteString(serverInfo->description); // gamename - m_InfoDetails.WriteByte(min(spectators, MAX_PROXY_CLIENTS)); // players - m_InfoDetails.WriteByte(min(slots, MAX_PROXY_CLIENTS)); // maxplayers + m_InfoDetails.WriteByte(Q_min(spectators, MAX_PROXY_CLIENTS)); // players + m_InfoDetails.WriteByte(Q_min(slots, MAX_PROXY_CLIENTS)); // maxplayers m_InfoDetails.WriteByte(PROTOCOL_VERSION); // protocol m_InfoDetails.WriteByte(GetServerType(HLST_TV)[0]); // server type (Indicates the type of server: HLTV Server) diff --git a/rehlds/HLTV/Proxy/src/ProxyClient.cpp b/rehlds/HLTV/Proxy/src/ProxyClient.cpp index 7d9cfd9..c340e50 100644 --- a/rehlds/HLTV/Proxy/src/ProxyClient.cpp +++ b/rehlds/HLTV/Proxy/src/ProxyClient.cpp @@ -89,7 +89,7 @@ bool ProxyClient::ProcessStringCmd(char *string) char *cmd = cmdLine.GetToken(0); for (auto& local_cmd : m_LocalCmdReg) { - if (!_stricmp(local_cmd.name, cmd)) { + if (!Q_stricmp(local_cmd.name, cmd)) { (this->*local_cmd.pfnCmd)(&cmdLine); return true; } @@ -143,7 +143,7 @@ void ProxyClient::CMD_JoinGame(TokenLine *cmd) if (m_Proxy->IsPublicGame()) { char string[64]; - _snprintf(string, sizeof(string), "connect %s\n", m_World->GetGameServerAddress()->ToString()); + Q_snprintf(string, sizeof(string), "connect %s\n", m_World->GetGameServerAddress()->ToString()); m_ClientChannel.m_reliableStream.WriteByte(svc_stufftext); m_ClientChannel.m_reliableStream.WriteString(string); @@ -177,7 +177,7 @@ void ProxyClient::CMD_IgnoreMsg(TokenLine *cmd) return; } - m_ChatEnabled = !atoi(cmd->GetToken(1)); + m_ChatEnabled = !Q_atoi(cmd->GetToken(1)); PrintfToClient("Global HLTV stats: spectators %i, slots %i, proxies %i\n", m_ChatEnabled ? "Spectator chat enabled.\n" : "Spectator chat disabled.\n"); } @@ -304,9 +304,9 @@ void ProxyClient::DownloadFile(char *fileName) return; const char szMD5[] = "!MD5"; - if (strstr(fileName, "..") || + if (Q_strstr(fileName, "..") || // ignore customization's - (strlen(fileName) == 36 && !_strnicmp(fileName, szMD5, sizeof(szMD5) - 1))) + (Q_strlen(fileName) == 36 && !_strnicmp(fileName, szMD5, sizeof(szMD5) - 1))) { DownloadFailed(fileName); return; diff --git a/rehlds/HLTV/Proxy/src/Status.cpp b/rehlds/HLTV/Proxy/src/Status.cpp index c6e3537..46ad212 100644 --- a/rehlds/HLTV/Proxy/src/Status.cpp +++ b/rehlds/HLTV/Proxy/src/Status.cpp @@ -148,7 +148,7 @@ char *Status::GetType() char *Status::GetStatusLine() { static char string[256]; - _snprintf(string, sizeof(string), "Global Status: Proxies %i, Slots %i, Spectators %i (max %i)\n", + Q_snprintf(string, sizeof(string), "Global Status: Proxies %i, Slots %i, Spectators %i (max %i)\n", m_NumberOfProxies, m_NumberOfSlots, m_NumberOfSpectators, m_MaxNumberOfSpectators); diff --git a/rehlds/HLTV/common/BaseClient.cpp b/rehlds/HLTV/common/BaseClient.cpp index f0fcbc9..5d4966f 100644 --- a/rehlds/HLTV/common/BaseClient.cpp +++ b/rehlds/HLTV/common/BaseClient.cpp @@ -269,7 +269,7 @@ bool BaseClient::ProcessStringCmd(char *string) char *cmd = cmdLine.GetToken(0); for (auto& local_cmd : m_LocalCmdReg) { - if (!_stricmp(local_cmd.name, cmd)) { + if (!Q_stricmp(local_cmd.name, cmd)) { (this->*local_cmd.pfnCmd)(&cmdLine); return true; } @@ -291,7 +291,7 @@ void BaseClient::CMD_Spawn(TokenLine *cmd) return; } - ReplySpawn(atoi(cmd->GetToken(1)), atoi(cmd->GetToken(2))); + ReplySpawn(Q_atoi(cmd->GetToken(1)), Q_atoi(cmd->GetToken(2))); } void BaseClient::CMD_New(TokenLine *cmd) @@ -346,7 +346,7 @@ void BaseClient::CMD_VoiceModEnable(TokenLine *cmd) } m_VoiceQuery = false; - m_VoiceEnabled = atoi(cmd->GetToken(1)) ? true : false; + m_VoiceEnabled = Q_atoi(cmd->GetToken(1)) ? true : false; UpdateVoiceMask(&m_ClientChannel.m_reliableStream); } @@ -389,7 +389,7 @@ void BaseClient::UpdateUserInfo(char *userinfostring) Q_strlcpy(buffer, m_Userinfo.ValueForKey("name")); SetName(buffer); - m_ClientType = atoi(m_Userinfo.ValueForKey("*hltv")); + m_ClientType = Q_atoi(m_Userinfo.ValueForKey("*hltv")); if (m_ClientType < TYPE_CLIENT) { m_System->DPrintf("WARNING! BaseClient::UpdateUserInfo: invalid client ype %i\n", m_ClientType); @@ -398,12 +398,12 @@ void BaseClient::UpdateUserInfo(char *userinfostring) string = m_Userinfo.ValueForKey("rate"); if (*string) { - m_ClientChannel.SetRate(atoi(string)); + m_ClientChannel.SetRate(Q_atoi(string)); } string = m_Userinfo.ValueForKey("cl_updaterate"); if (*string) { - m_ClientChannel.SetUpdateRate(atoi(string)); + m_ClientChannel.SetUpdateRate(Q_atoi(string)); } } @@ -413,7 +413,7 @@ void BaseClient::PrintfToClient(char *fmt, ...) static char string[1024]; va_start(argptr, fmt); - _vsnprintf(string, sizeof(string), fmt, argptr); + Q_vsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); m_ClientChannel.m_reliableStream.WriteByte(svc_print); @@ -587,7 +587,7 @@ char *BaseClient::GetStatusLine() static char string[256]; m_ClientChannel.GetFlowStats(&in, &out); - _snprintf(string, sizeof(string), + Q_snprintf(string, sizeof(string), "ID: %i, Name \"%s\", Time %s, IP %s, In %.2f, Out %.2f.\n", GetSerial(), m_ClientName, @@ -640,12 +640,12 @@ void BaseClient::SetName(char *newName) COM_TrimSpace(newName, temp); const int len = sizeof(m_ClientName); - if (strlen(temp) >= len) { + if (Q_strlen(temp) >= len) { temp[len] = '\0'; } - if (!temp[0] || !_stricmp(temp, "console")) { - strcpy(temp, "unnamed"); + if (!temp[0] || !Q_stricmp(temp, "console")) { + Q_strcpy(temp, "unnamed"); } Q_strlcpy(m_ClientName, temp); @@ -773,7 +773,7 @@ void BaseClient::Reset() m_DeltaFrameSeqNr = 0; m_ClientDelta = 0; - memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); + Q_memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); m_VoiceQuery = true; m_ClientChannel.Clear(); } diff --git a/rehlds/HLTV/common/BitBuffer.cpp b/rehlds/HLTV/common/BitBuffer.cpp index 927aa4c..d309a4b 100644 --- a/rehlds/HLTV/common/BitBuffer.cpp +++ b/rehlds/HLTV/common/BitBuffer.cpp @@ -136,7 +136,7 @@ bool BitBuffer::Resize(unsigned int size) void BitBuffer::Clear() { - memset(m_Data, 0, m_MaxSize); + Q_memset(m_Data, 0, m_MaxSize); m_CurByte = m_Data; m_CurSize = 0; @@ -330,7 +330,7 @@ bool BitBuffer::ReadBuf(int iSize, void *pbuf) } else { - memcpy(pbuf, m_CurByte, iSize); + Q_memcpy(pbuf, m_CurByte, iSize); m_CurByte += iSize; } @@ -562,7 +562,7 @@ void BitBuffer::WriteString(const char *p) { if (p) { - WriteBuf(p, strlen(p) + 1); + WriteBuf(p, Q_strlen(p) + 1); } else { @@ -596,7 +596,7 @@ void BitBuffer::WriteBuf(const void *buf, int iSize) } else { - memcpy(m_CurByte, buf, iSize); + Q_memcpy(m_CurByte, buf, iSize); m_CurByte += iSize; } } @@ -867,7 +867,7 @@ void BitBuffer::FastClear() iSize = m_MaxSize; } - memset(m_Data, 0, iSize); + Q_memset(m_Data, 0, iSize); m_CurByte = m_Data; m_CurSize = 0; diff --git a/rehlds/HLTV/common/DemoFile.cpp b/rehlds/HLTV/common/DemoFile.cpp index 15d69c0..611c7e2 100644 --- a/rehlds/HLTV/common/DemoFile.cpp +++ b/rehlds/HLTV/common/DemoFile.cpp @@ -52,8 +52,8 @@ void DemoFile::Init(IWorld *world, IServer *server, NetChannel *channel) void DemoFile::Reset() { - memset(m_FileName, 0, sizeof(m_FileName)); - memset(&m_zeroDemoInfo, 0, sizeof(m_zeroDemoInfo)); + Q_memset(m_FileName, 0, sizeof(m_FileName)); + Q_memset(&m_zeroDemoInfo, 0, sizeof(m_zeroDemoInfo)); CloseFile(); m_Continuous = true; @@ -259,8 +259,8 @@ bool DemoFile::StartRecording(char *newName) return false; } - memset(&m_demoHeader, 0, sizeof(m_demoHeader)); - strcpy(m_demoHeader.szFileStamp, "HLDEMO"); + Q_memset(&m_demoHeader, 0, sizeof(m_demoHeader)); + Q_strcpy(m_demoHeader.szFileStamp, "HLDEMO"); COM_FileBase(m_World->GetLevelName(), m_demoHeader.szMapName); COM_FileBase(m_World->GetGameDir(), m_demoHeader.szDllDir); @@ -271,8 +271,8 @@ bool DemoFile::StartRecording(char *newName) m_demoHeader.nDirectoryOffset = 0; m_FileSystem->Write(&m_demoHeader, sizeof(m_demoHeader), m_FileHandle); - memset(&m_loadEntry, 0, sizeof(m_loadEntry)); - strcpy(m_loadEntry.szDescription, "LOADING"); + Q_memset(&m_loadEntry, 0, sizeof(m_loadEntry)); + Q_strcpy(m_loadEntry.szDescription, "LOADING"); m_loadEntry.nEntryType = DEMO_STARTUP; m_loadEntry.nOffset = m_FileSystem->Tell(m_FileHandle); @@ -293,8 +293,8 @@ bool DemoFile::StartRecording(char *newName) m_loadEntry.nFileLength = m_FileSystem->Tell(m_FileHandle) - m_loadEntry.nOffset; - memset(&m_gameEntry, 0, sizeof(m_gameEntry)); - _snprintf(m_gameEntry.szDescription, sizeof(m_gameEntry.szDescription), "Playback"); + Q_memset(&m_gameEntry, 0, sizeof(m_gameEntry)); + Q_snprintf(m_gameEntry.szDescription, sizeof(m_gameEntry.szDescription), "Playback"); m_gameEntry.nEntryType = DEMO_NORMAL; m_gameEntry.nOffset = m_FileSystem->Tell(m_FileHandle); @@ -335,8 +335,8 @@ bool DemoFile::LoadDemo(char *demoname) Q_strlcpy(m_FileName, demoname); Q_strlwr(m_FileName); - if (!strstr(m_FileName, ".dem")) { - strcat(m_FileName, ".dem"); + if (!Q_strstr(m_FileName, ".dem")) { + Q_strlcat(m_FileName, ".dem"); } m_FileHandle = m_FileSystem->Open(m_FileName, "rb"); @@ -345,10 +345,10 @@ bool DemoFile::LoadDemo(char *demoname) return false; } - memset(&m_demoHeader, 0, sizeof(m_demoHeader)); + Q_memset(&m_demoHeader, 0, sizeof(m_demoHeader)); m_FileSystem->Read(&m_demoHeader, sizeof(m_demoHeader), m_FileHandle); - if (strcmp(m_demoHeader.szFileStamp, "HLDEMO") != 0) { + if (Q_strcmp(m_demoHeader.szFileStamp, "HLDEMO") != 0) { m_System->Printf("%s is not a HL demo file.\n", m_FileName); m_FileSystem->Close(m_FileHandle); return false; @@ -382,7 +382,7 @@ bool DemoFile::LoadDemo(char *demoname) m_nextReadTime = m_System->GetTime(); m_Continuous = true; - memset(&m_ServerInfo, 0, sizeof(m_ServerInfo)); + Q_memset(&m_ServerInfo, 0, sizeof(m_ServerInfo)); Q_strlcpy(m_ServerInfo.address, m_DemoChannel->m_remote_address.ToBaseString()); Q_strlcpy(m_ServerInfo.name, m_FileName); diff --git a/rehlds/HLTV/common/DirectorCmd.cpp b/rehlds/HLTV/common/DirectorCmd.cpp index 8b62c7d..6ee3de1 100644 --- a/rehlds/HLTV/common/DirectorCmd.cpp +++ b/rehlds/HLTV/common/DirectorCmd.cpp @@ -178,7 +178,7 @@ bool DirectorCmd::GetSoundData(char *name, float &volume) } m_Data.Reset(); - strcpy(name, m_Data.ReadString()); + Q_strcpy(name, m_Data.ReadString()); volume = m_Data.ReadFloat(); return true; @@ -241,7 +241,7 @@ bool DirectorCmd::GetMessageData(int &effect, int &color, vec_t *position, float fadeout = m_Data.ReadFloat(); holdtime = m_Data.ReadFloat(); fxtime = m_Data.ReadFloat(); - strcpy(text, m_Data.ReadString()); + Q_strcpy(text, m_Data.ReadString()); return true; } @@ -267,7 +267,7 @@ bool DirectorCmd::GetBannerData(char *filename) } m_Data.Reset(); - strcpy(filename, m_Data.ReadString()); + Q_strcpy(filename, m_Data.ReadString()); return true; } @@ -279,7 +279,7 @@ bool DirectorCmd::GetStuffTextData(char *commands) } m_Data.Reset(); - strcpy(commands, m_Data.ReadString()); + Q_strcpy(commands, m_Data.ReadString()); return true; } @@ -369,7 +369,7 @@ void DirectorCmd::SetCamPathData(vec_t *position, vec_t *angles, float fov, int void DirectorCmd::SetSoundData(char *name, float volume) { - int len = strlen(name); + int len = Q_strlen(name); m_Type = DRC_CMD_SOUND; Resize(len + 5); @@ -392,7 +392,7 @@ void DirectorCmd::SetTime(float time) void DirectorCmd::SetMessageData(int effect, unsigned int color, vec_t *position, float fadein, float fadeout, float holdtime, float fxtime, char *text) { - int len = strlen(text); + int len = Q_strlen(text); m_Type = DRC_CMD_MESSAGE; Resize(len + 30); @@ -434,7 +434,7 @@ void DirectorCmd::SetBannerData(char *filename) { m_Type = DRC_CMD_BANNER; - int len = strlen(filename); + int len = Q_strlen(filename); Resize(len + 1); m_Data.WriteString(filename); } @@ -443,7 +443,7 @@ void DirectorCmd::SetStuffTextData(char *commands) { m_Type = DRC_CMD_STUFFTEXT; - int len = strlen(commands); + int len = Q_strlen(commands); Resize(len + 1); m_Data.WriteString(commands); } @@ -496,7 +496,7 @@ bool DirectorCmd::ReadFromStream(BitBuffer *stream) stream->SkipBytes(29); string = stream->ReadString(); - length = strlen(string); + length = Q_strlen(string); Resize(length + 30); m_Data.WriteBuf(start, 29); @@ -506,7 +506,7 @@ bool DirectorCmd::ReadFromStream(BitBuffer *stream) case DRC_CMD_SOUND: { string = stream->ReadString(); - length = strlen(string); + length = Q_strlen(string); Resize(length + 5); m_Data.WriteBuf(string, length + 1); @@ -521,7 +521,7 @@ bool DirectorCmd::ReadFromStream(BitBuffer *stream) case DRC_CMD_BANNER: { string = stream->ReadString(); - length = strlen(string) + 1; + length = Q_strlen(string) + 1; Resize(length); m_Data.WriteBuf(string, length); @@ -530,7 +530,7 @@ bool DirectorCmd::ReadFromStream(BitBuffer *stream) case DRC_CMD_STUFFTEXT: { string = stream->ReadString(); - length = strlen(string) + 1; + length = Q_strlen(string) + 1; Resize(length); m_Data.WriteBuf(string, length); @@ -593,68 +593,68 @@ char *DirectorCmd::ToString() char t2[1024]; static char s[1024]; - memset(s, 0, sizeof(s)); + Q_memset(s, 0, sizeof(s)); switch (m_Type) { case DRC_CMD_START: - sprintf(s, "%s", t1); + Q_sprintf(s, "%s", t1); break; case DRC_CMD_EVENT: GetEventData(i1, i2, i3); - sprintf(s, "%s %i %i %i", t1, i1, i2, i3); + Q_sprintf(s, "%s %i %i %i", t1, i1, i2, i3); break; case DRC_CMD_MODE: GetModeData(i1); - sprintf(s, "%s %i", t1, i1); + Q_sprintf(s, "%s %i", t1, i1); break; case DRC_CMD_CAMERA: GetCameraData(v1, v2, f1, i1); - sprintf(s, "%s (%.1f %.1f %.1f) (%.1f %.1f %.1f) %.1f %i", t1, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], f1, i1); + Q_sprintf(s, "%s (%.1f %.1f %.1f) (%.1f %.1f %.1f) %.1f %i", t1, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], f1, i1); break; case DRC_CMD_TIMESCALE: GetTimeScaleData(f1); - sprintf(s, "%s %.2f", t1, f1); + Q_sprintf(s, "%s %.2f", t1, f1); break; case DRC_CMD_MESSAGE: GetMessageData(i1, i2, v1, f1, f2, f3, f4, t2); - sprintf(s, "%s \"%s\" %i %x (%.2f %.2f) %.1f, %.1f %.1f %.1f", t1, t2, i1, i2, v1[0], v1[1], f1, f2, f3, f4); + Q_sprintf(s, "%s \"%s\" %i %x (%.2f %.2f) %.1f, %.1f %.1f %.1f", t1, t2, i1, i2, v1[0], v1[1], f1, f2, f3, f4); break; case DRC_CMD_SOUND: GetSoundData(t2, f1); - sprintf(s, "%s \"%s\" %.2f", t1, t2, f1); + Q_sprintf(s, "%s \"%s\" %.2f", t1, t2, f1); break; case DRC_CMD_STATUS: GetStatusData(i1, i2, i3); - sprintf(s, "%s %i %i %i", t1, i1, i2, i3); + Q_sprintf(s, "%s %i %i %i", t1, i1, i2, i3); break; case DRC_CMD_BANNER: GetBannerData(t2); - sprintf(s, "%s \"%s\"", t1, t2); + Q_sprintf(s, "%s \"%s\"", t1, t2); break; case DRC_CMD_STUFFTEXT: GetStuffTextData(t2); - sprintf(s, "%s \"%s\"", t1, t2); + Q_sprintf(s, "%s \"%s\"", t1, t2); break; case DRC_CMD_CHASE: GetChaseData(i1, i2, f1, i3); - sprintf(s, "%s %i %i %.1f %i", t1, i1, i2, f1, i3); + Q_sprintf(s, "%s %i %i %.1f %i", t1, i1, i2, f1, i3); break; case DRC_CMD_INEYE: GetInEyeData(i1); - sprintf(s, "%s %i", t1, i1); + Q_sprintf(s, "%s %i", t1, i1); break; case DRC_CMD_MAP: GetMapData(i1, f1, f2); - sprintf(s, "%s %i %.1f %.1f", t1, i1, f1, f2); + Q_sprintf(s, "%s %i %.1f %.1f", t1, i1, f1, f2); break; case DRC_CMD_CAMPATH: GetCamPathData(v1, v2, f1, i1); - sprintf(s, "%s (%.1f %.1f %.1f) (%.1f %.1f %.1f) %.1f %i", t1, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], f1, i1); + Q_sprintf(s, "%s (%.1f %.1f %.1f) (%.1f %.1f %.1f) %.1f %i", t1, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], f1, i1); break; case DRC_CMD_WAYPOINTS: GetWayPointsData(i1); - sprintf(s, "%s %i", t1, i1); + Q_sprintf(s, "%s %i", t1, i1); break; default: case DRC_CMD_NONE: diff --git a/rehlds/HLTV/common/InfoString.cpp b/rehlds/HLTV/common/InfoString.cpp index 1f92df5..3d61971 100644 --- a/rehlds/HLTV/common/InfoString.cpp +++ b/rehlds/HLTV/common/InfoString.cpp @@ -31,7 +31,7 @@ InfoString::InfoString(char *string, unsigned int maxSize) : m_String(nullptr), m_MaxSize(0) { - unsigned int len = strlen(string) + 1; + unsigned int len = Q_strlen(string) + 1; if (len < maxSize) { len = maxSize; } @@ -54,7 +54,7 @@ InfoString::InfoString(unsigned int maxSize) InfoString::InfoString(char *string) : m_String(nullptr), m_MaxSize(0) { - unsigned int len = strlen(string) + 1; + unsigned int len = Q_strlen(string) + 1; if (len < MAX_INFO_LEN) { len = MAX_INFO_LEN; } @@ -77,12 +77,11 @@ bool InfoString::SetString(char *string) return false; } - if (strlen(string) >= m_MaxSize) { + if (Q_strlen(string) >= m_MaxSize) { return false; } - strncpy(m_String, string, m_MaxSize - 1); - m_String[m_MaxSize - 1] = '\0'; + Q_strnlcpy(m_String, string, m_MaxSize); return true; } @@ -95,9 +94,8 @@ void InfoString::SetMaxSize(unsigned int maxSize) if (m_String) { - if (maxSize > strlen(m_String)) { - strncpy(newBuffer, m_String, maxSize - 1); - newBuffer[maxSize - 1] = '\0'; + if (maxSize > Q_strlen(m_String)) { + Q_strnlcpy(newBuffer, m_String, maxSize); } Mem_Free(m_String); @@ -114,13 +112,13 @@ int InfoString::GetMaxSize() int InfoString::GetCurrentSize() { - return strlen(m_String); + return Q_strlen(m_String); } void InfoString::Clear() { if (m_String) { - memset(m_String, 0, m_MaxSize); + Q_memset(m_String, 0, m_MaxSize); } } @@ -200,7 +198,7 @@ char *InfoString::ValueForKey(const char *key) *c = '\0'; - if (!strcmp(key, pkey)) + if (!Q_strcmp(key, pkey)) { c = value[valueindex]; valueindex = (valueindex + 1) % MAX_INFO_VALUES; @@ -223,11 +221,11 @@ bool InfoString::RemoveKey(const char *key) s = m_String; - if (strchr(key, '\\')) { + if (Q_strchr(key, '\\')) { return false; } - cmpsize = strlen(key); + cmpsize = Q_strlen(key); if (cmpsize > MAX_INFO_LEN - 1) { cmpsize = MAX_INFO_LEN - 1; } @@ -292,10 +290,10 @@ bool InfoString::RemoveKey(const char *key) *c = '\0'; // Compare keys - if (!strncmp(key, pkey, cmpsize) ) + if (!Q_strncmp(key, pkey, cmpsize) ) { found = true; - strcpy_safe(start, s); // remove this part + Q_strcpy_s(start, s); // remove this part s = start; // continue searching } } @@ -374,7 +372,7 @@ void InfoString::RemovePrefixedKeys(char prefix) // Compare prefix if (pkey[0] == prefix) { - strcpy_safe(start, s); // remove this part + Q_strcpy_s(start, s); // remove this part s = start; // continue searching } } @@ -383,30 +381,30 @@ void InfoString::RemovePrefixedKeys(char prefix) bool InfoString::SetValueForStarKey(const char *key, const char *value) { char newtoken[MAX_INFO_LEN + 4]; - if (strstr(key, "\\") || strstr(value, "\\")) { + if (Q_strstr(key, "\\") || Q_strstr(value, "\\")) { return false; } - if (strstr(key, "\"") || strstr(value, "\"")) { + if (Q_strstr(key, "\"") || Q_strstr(value, "\"")) { return false; } - if (strlen(key) > MAX_INFO_KEY || strlen(value) > MAX_INFO_VALUE) { + if (Q_strlen(key) > MAX_INFO_KEY || Q_strlen(value) > MAX_INFO_VALUE) { return false; } // Remove current key/value and return if we doesn't specified to set a value RemoveKey(key); - if (!strlen(value)) { + if (!Q_strlen(value)) { return true; } // Create key/value pair - _snprintf(newtoken, sizeof(newtoken), "\\%s\\%s", key, value); + Q_snprintf(newtoken, sizeof(newtoken), "\\%s\\%s", key, value); - int length = strlen(m_String); - if ((length + strlen(newtoken)) < m_MaxSize) + int length = Q_strlen(m_String); + if ((length + Q_strlen(newtoken)) < m_MaxSize) { char *v = newtoken; char *s = m_String + length; diff --git a/rehlds/HLTV/common/NetAddress.cpp b/rehlds/HLTV/common/NetAddress.cpp index 03f9eaa..2ee99c0 100644 --- a/rehlds/HLTV/common/NetAddress.cpp +++ b/rehlds/HLTV/common/NetAddress.cpp @@ -95,20 +95,20 @@ void NetAddress::FromStream(BitBuffer *stream) char *NetAddress::ToString() { - _snprintf(m_String, sizeof(m_String), "%i.%i.%i.%i:%i", m_IP[0], m_IP[1], m_IP[2], m_IP[3], ntohs(m_Port)); + Q_snprintf(m_String, sizeof(m_String), "%i.%i.%i.%i:%i", m_IP[0], m_IP[1], m_IP[2], m_IP[3], ntohs(m_Port)); return m_String; } char *NetAddress::ToBaseString() { - _snprintf(m_String, sizeof(m_String), "%i.%i.%i.%i", m_IP[0], m_IP[1], m_IP[2], m_IP[3]); + Q_snprintf(m_String, sizeof(m_String), "%i.%i.%i.%i", m_IP[0], m_IP[1], m_IP[2], m_IP[3]); return m_String; } void NetAddress::FromNetAddress(NetAddress *adr) { if (!adr) { - memset(m_IP, 0, sizeof(m_IP)); + Q_memset(m_IP, 0, sizeof(m_IP)); m_Port = 0; return; } @@ -152,7 +152,7 @@ void NetAddress::Clear() m_IP[0] = 0; m_Port = 0; - memset(m_String, 0, sizeof(m_String)); + Q_memset(m_String, 0, sizeof(m_String)); } bool NetAddress::IsSubAdress(NetAddress *adr) diff --git a/rehlds/HLTV/common/NetChannel.cpp b/rehlds/HLTV/common/NetChannel.cpp index 61c997f..ac1240a 100644 --- a/rehlds/HLTV/common/NetChannel.cpp +++ b/rehlds/HLTV/common/NetChannel.cpp @@ -93,10 +93,10 @@ void NetChannel::OutOfBandPrintf(const char *format, ...) *(int *)string = CONNECTIONLESS_HEADER; va_start(argptr, format); - _vsnprintf(&string[4], sizeof(string) - 4, format, argptr); + Q_vsnprintf(&string[4], sizeof(string) - 4, format, argptr); va_end(argptr); - data.SkipBytes(strlen(string)); + data.SkipBytes(Q_strlen(string)); m_Socket->SendPacket(&m_remote_address, data.GetData(), data.CurrentSize()); } } @@ -210,8 +210,8 @@ void NetChannel::Clear() m_tempBufferSize = 0; m_reliableOutSize = 0; - memset(m_reliableOutBuffer, 0, sizeof(m_reliableOutBuffer)); - memset(m_flow, 0, sizeof(m_flow)); + Q_memset(m_reliableOutBuffer, 0, sizeof(m_reliableOutBuffer)); + Q_memset(m_flow, 0, sizeof(m_flow)); m_reliableStream.Clear(); m_unreliableStream.Clear(); @@ -431,7 +431,7 @@ void NetChannel::TransmitOutgoing() if (send_from_regular) { - memcpy(m_reliableOutBuffer, m_reliableStream.GetData(), m_reliableStream.CurrentSize()); + Q_memcpy(m_reliableOutBuffer, m_reliableStream.GetData(), m_reliableStream.CurrentSize()); m_reliableOutSize = m_reliableStream.CurrentSize(); m_reliableStream.FastClear(); @@ -469,7 +469,7 @@ void NetChannel::TransmitOutgoing() m_System->Printf("TODO! NetChannel::Transmit: system file support\n"); } - memcpy(m_reliableOutBuffer + m_reliableOutSize, pbuf->data, pbuf->size); + Q_memcpy(m_reliableOutBuffer + m_reliableOutSize, pbuf->data, pbuf->size); m_reliableOutSize += pbuf->size; m_frag_length[i] = pbuf->size; @@ -571,7 +571,7 @@ void NetChannel::TransmitOutgoing() } m_last_send = m_System->GetTime(); - m_cleartime = max(m_send_interval, (data.CurrentSize() + UDP_HEADER_SIZE) * (1.0 / m_max_bandwidth_rate)) + m_last_send; + m_cleartime = Q_max(m_send_interval, (data.CurrentSize() + UDP_HEADER_SIZE) * (1.0 / m_max_bandwidth_rate)) + m_last_send; } NetChannel::fragbuf_t *NetChannel::FindBufferById(fragbuf_t **pplist, int id, bool allocate) @@ -801,7 +801,7 @@ void NetChannel::ProcessIncoming(unsigned char *data, int size) pbuf = FindBufferById(&m_incomingbufs[i], fragid[i], true); if (pbuf) { - memcpy(pbuf->data, message.GetData() + message.CurrentSize() + frag_offset[i], frag_length[i]); + Q_memcpy(pbuf->data, message.GetData() + message.CurrentSize() + frag_offset[i], frag_length[i]); pbuf->size = frag_length[i]; } else @@ -817,7 +817,7 @@ void NetChannel::ProcessIncoming(unsigned char *data, int size) int wpos = message.CurrentSize() + frag_offset[i]; int rpos = wpos + frag_length[i]; - memmove(message.GetData() + wpos, message.GetData() + rpos, message.GetMaxSize() - rpos); + Q_memmove(message.GetData() + wpos, message.GetData() + rpos, message.GetMaxSize() - rpos); message.m_MaxSize -= frag_length[i]; for (j = i + 1; j < MAX_STREAMS; j++) @@ -949,14 +949,14 @@ bool NetChannel::CreateFragmentsFromBuffer(void *buffer, int size, int streamtyp if (!BZ2_bzBuffToBuffCompress((char *)compressed, &compressedSize, (char *)buffer, size, 9, 0, 30)) { m_System->DPrintf("Compressing split packet (%d -> %d bytes)\n", size, compressedSize); - memcpy(buffer, hdr, sizeof(hdr)); + Q_memcpy(buffer, hdr, sizeof(hdr)); if (streamtype == FRAG_FILE_STREAM) { - memcpy((char *)buffer + 4, &size, sizeof(int)); + Q_memcpy((char *)buffer + 4, &size, sizeof(int)); header_size = 8; } - memcpy((char *)buffer + header_size, compressed, compressedSize); + Q_memcpy((char *)buffer + header_size, compressed, compressedSize); size = header_size + compressedSize; } @@ -967,7 +967,7 @@ bool NetChannel::CreateFragmentsFromBuffer(void *buffer, int size, int streamtyp pos = 0; while (remaining > 0) { - sendsize = min(remaining, chunksize); + sendsize = Q_min(remaining, chunksize); remaining -= sendsize; buf = (fragbuf_t *)Mem_ZeroMalloc(sizeof(fragbuf_t)); @@ -982,16 +982,16 @@ bool NetChannel::CreateFragmentsFromBuffer(void *buffer, int size, int streamtyp { firstfragment = false; - unsigned int len = strlen(filename) + 1; - memcpy(buf->data, filename, len); + unsigned int len = Q_strlen(filename) + 1; + Q_memcpy(buf->data, filename, len); sendsize -= len; - memcpy(&buf->data[len], (char *)buffer + pos, sendsize); + Q_memcpy(&buf->data[len], (char *)buffer + pos, sendsize); buf->size = len + sendsize; } else { - memcpy(buf->data, (char *)buffer + pos, sendsize); + Q_memcpy(buf->data, (char *)buffer + pos, sendsize); buf->size = sendsize; } @@ -1128,7 +1128,7 @@ void NetChannel::SetConnected(bool flag) void NetChannel::SetRate(int newRate) { - m_max_bandwidth_rate = clamp(newRate, 1000, 20000); + m_max_bandwidth_rate = Q_clamp(newRate, 1000, 20000); } void NetChannel::GetFlowStats(float *avgInKBSec, float *avgOutKBSec) @@ -1264,13 +1264,13 @@ bool NetChannel::CopyFileFragments() filecontent.Reset(); Q_strlcpy(filename, filecontent.ReadString()); - if (!strlen(filename)) { + if (!Q_strlen(filename)) { m_System->Printf("File fragment received with no filename\n"); FlushIncoming(FRAG_FILE_STREAM); return false; } - if (strstr(filename, "..")) { + if (Q_strstr(filename, "..")) { m_System->Printf("File fragment received with relative path, ignoring\n"); FlushIncoming(FRAG_FILE_STREAM); return false; @@ -1279,7 +1279,7 @@ bool NetChannel::CopyFileFragments() // TODO: Here is the missing code. // TODO: Check me, value of return function only false. - totalSize -= strlen(filename) - 1; + totalSize -= Q_strlen(filename) - 1; m_incomingbufs[FRAG_FILE_STREAM] = nullptr; return false; diff --git a/rehlds/HLTV/common/common.cpp b/rehlds/HLTV/common/common.cpp index 9e4bf33..76d0ecd 100644 --- a/rehlds/HLTV/common/common.cpp +++ b/rehlds/HLTV/common/common.cpp @@ -49,8 +49,8 @@ int COM_BuildNumber() d += mond[m]; } - d += atoi(&date[4]) - 1; - y = atoi(&date[7]) - 1900; + d += Q_atoi(&date[4]) - 1; + y = Q_atoi(&date[7]) - 1900; b = d + (int)((y - 1) * 365.25); if (((y % 4) == 0) && m > 1) @@ -96,12 +96,12 @@ char *COM_GetBaseDir() if (GetModuleFileName((HMODULE)nullptr, basedir, sizeof(basedir))) { - char *pBuffer = strrchr(basedir, '\\'); + char *pBuffer = Q_strrchr(basedir, '\\'); if (pBuffer && *pBuffer) pBuffer[1] = '\0'; - int j = strlen(basedir); + int j = Q_strlen(basedir); if (j > 0 && (basedir[j - 1] == '\\' || basedir[j - 1] == '/')) basedir[j - 1] = '\0'; } @@ -117,13 +117,13 @@ char *COM_GetBaseDir() static char basedir[MAX_PATH]; basedir[0] = '\0'; - strcpy(basedir, g_szEXEName); - char *pBuffer = strrchr(basedir, '/'); + Q_strcpy(basedir, g_szEXEName); + char *pBuffer = Q_strrchr(basedir, '/'); if (pBuffer && *pBuffer) pBuffer[1] = '\0'; - int j = strlen(basedir); + int j = Q_strlen(basedir); if (j > 0 && (basedir[j - 1] == '\\' || basedir[j - 1] == '/')) basedir[j - 1] = '\0'; @@ -157,7 +157,7 @@ void COM_FileBase(char *in, char *out) { *out = '\0'; - int len = strlen(in); + int len = Q_strlen(in); if (len <= 0) { return; } @@ -176,7 +176,8 @@ void COM_FileBase(char *in, char *out) start++; len = end - start; - strncpy(out, start, len); + + Q_strncpy(out, start, len); out[len] = '\0'; } @@ -284,7 +285,7 @@ char *COM_VarArgs(char *format, ...) static char string[1024]; va_start(argptr, format); - _vsnprintf(string, sizeof(string), format, argptr); + Q_vsnprintf(string, sizeof(string), format, argptr); va_end(argptr); return string; @@ -328,12 +329,12 @@ char *COM_BinPrintf(unsigned char *buf, int length) { char szChunk[10]; static char szReturn[4096]; - memset(szReturn, 0, sizeof(szReturn)); + Q_memset(szReturn, 0, sizeof(szReturn)); for (int i = 0; i < length; i++) { - _snprintf(szChunk, sizeof(szChunk), "%02x", buf[i]); - strncat(szReturn, szChunk, sizeof(szReturn) - strlen(szReturn) - 1); + Q_snprintf(szChunk, sizeof(szChunk), "%02x", buf[i]); + Q_strlcat(szReturn, szChunk); } return szReturn; @@ -346,11 +347,11 @@ char *COM_FormatTime(float seconds) int hours = (int)seconds / 3600; if (hours > 0) { - _snprintf(time, sizeof(time), "%02i:%2i:%02i", hours, (int)seconds / 60, (int)seconds % 60); + Q_snprintf(time, sizeof(time), "%02i:%2i:%02i", hours, (int)seconds / 60, (int)seconds % 60); } else { - _snprintf(time, sizeof(time), "%02i:%02i", (int)seconds / 60, (int)seconds % 60); + Q_snprintf(time, sizeof(time), "%02i:%02i", (int)seconds / 60, (int)seconds % 60); } return time; @@ -413,7 +414,7 @@ void COM_TrimSpace(const char *source, char *dest) start++; } - int end = strlen(source) - 1; + int end = Q_strlen(source) - 1; while (end > 0 && COM_IsWhiteSpace(source[end])) { end--; } @@ -422,7 +423,7 @@ void COM_TrimSpace(const char *source, char *dest) int length = end - start; if (length > 0) { - strncpy(dest, &source[start], length); + Q_strncpy(dest, &source[start], length); } else length = 0; diff --git a/rehlds/HLTV/common/mathlib.cpp b/rehlds/HLTV/common/mathlib.cpp index 8b3f96f..fb8e5ab 100644 --- a/rehlds/HLTV/common/mathlib.cpp +++ b/rehlds/HLTV/common/mathlib.cpp @@ -57,14 +57,14 @@ float TriangleDiameter(const vec_t *v1, vec_t *v2, vec_t *v3) } if (l3 > l2 && l3 > l1) { - return sqrt(l3); + return Q_sqrt(l3); } if (l2 > l3 && l2 > l1) { - return sqrt(l2); + return Q_sqrt(l2); } - return sqrt(l1); + return Q_sqrt(l1); } float VectorNormalize(vec_t *v) @@ -106,7 +106,7 @@ void VectorAngles(const float *forward, float *angles) if (yaw < 0) yaw += 360; - tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]); + tmp = Q_sqrt(forward[0] * forward[0] + forward[1] * forward[1]); pitch = float(atan2(forward[2], tmp) * 180 / M_PI); if (pitch < 0) pitch += 360; @@ -119,7 +119,7 @@ void VectorAngles(const float *forward, float *angles) void VectorRAngles(const float *v, float *a) { - a[0] = atan2(v[2], sqrt(v[0] * v[0] + v[1] * v[1])); + a[0] = atan2(v[2], Q_sqrt(v[0] * v[0] + v[1] * v[1])); a[1] = atan2(v[1], v[0]); NormalizeRAngles(a); } @@ -381,7 +381,7 @@ void Normal2Plane(vec_t *v1, vec_t *v2, vec_t *v3) float Length(const vec_t *v) { - return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + return Q_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); } float DotProduct(const vec_t *v1, const vec_t *v2) diff --git a/rehlds/HLTV/common/md5.cpp b/rehlds/HLTV/common/md5.cpp index 801b933..921760d 100644 --- a/rehlds/HLTV/common/md5.cpp +++ b/rehlds/HLTV/common/md5.cpp @@ -264,12 +264,12 @@ char *MD5_Print(unsigned char *hash) char szChunk[10]; int i; - memset(szReturn, 0, sizeof(szReturn)); + Q_memset(szReturn, 0, sizeof(szReturn)); for (i = 0; i < 16; i++) { - _snprintf(szChunk, sizeof(szChunk), "%02x", hash[i]); - strncat(szReturn, szChunk, sizeof(szReturn) - strlen(szReturn) - 1); + Q_snprintf(szChunk, sizeof(szChunk), "%02x", hash[i]); + Q_strlcat(szReturn, szChunk); } return szReturn; @@ -280,36 +280,32 @@ char *MD5_GetCDKeyHash(const char *key) static char szHashedKeyBuffer[256]; char szKeyBuffer[256]; - int nKeyLength = strlen(key); + int nKeyLength = Q_strlen(key); if (nKeyLength <= 0 || nKeyLength > 255) { return nullptr; } - strncpy(szKeyBuffer, key, sizeof(szKeyBuffer) - 1); - szKeyBuffer[sizeof(szKeyBuffer) - 1] = '\0'; + Q_strlcpy(szKeyBuffer, key); szKeyBuffer[nKeyLength] = '\0'; MD5Context_t ctx; unsigned char digest[16]; - memset(&ctx, 0, sizeof(ctx)); - memset(digest, 0, sizeof(digest)); - memset(szHashedKeyBuffer, 0, sizeof(szHashedKeyBuffer)); + Q_memset(&ctx, 0, sizeof(ctx)); + Q_memset(digest, 0, sizeof(digest)); + Q_memset(szHashedKeyBuffer, 0, sizeof(szHashedKeyBuffer)); MD5_Init(&ctx); MD5_Update(&ctx, (unsigned char *)szKeyBuffer, nKeyLength); MD5_Final(digest, &ctx); - strncpy(szHashedKeyBuffer, MD5_Print(digest), sizeof(szHashedKeyBuffer) - 1); - szHashedKeyBuffer[sizeof(szHashedKeyBuffer) - 1] = '\0'; - - return szHashedKeyBuffer; + return Q_strlcpy(szHashedKeyBuffer, MD5_Print(digest)); } void MD5_Hash_Mem(unsigned char *digest, unsigned char *mem, int size) { MD5Context_t ctx; - memset(&ctx, 0, sizeof(ctx)); + Q_memset(&ctx, 0, sizeof(ctx)); MD5_Init(&ctx); MD5_Update(&ctx, mem, size); diff --git a/rehlds/common/BaseSystemModule.cpp b/rehlds/common/BaseSystemModule.cpp index 7081b33..3233b54 100644 --- a/rehlds/common/BaseSystemModule.cpp +++ b/rehlds/common/BaseSystemModule.cpp @@ -35,7 +35,7 @@ BaseSystemModule::BaseSystemModule() m_SystemTime = 0; m_State = MODULE_UNDEFINED; - memset(m_Name, 0, sizeof(m_Name)); + Q_memset(m_Name, 0, sizeof(m_Name)); } char *BaseSystemModule::GetName() diff --git a/rehlds/common/ObjectDictionary.cpp b/rehlds/common/ObjectDictionary.cpp index d7e6902..84a0f88 100644 --- a/rehlds/common/ObjectDictionary.cpp +++ b/rehlds/common/ObjectDictionary.cpp @@ -34,7 +34,7 @@ ObjectDictionary::ObjectDictionary() m_findKey = 0; m_entries = nullptr; - memset(m_cache, 0, sizeof(m_cache)); + Q_memset(m_cache, 0, sizeof(m_cache)); m_cacheIndex = 0; m_size = 0; @@ -163,7 +163,7 @@ int ObjectDictionary::FindClosestAsIndex(float key) void ObjectDictionary::ClearCache() { - memset(m_cache, 0, sizeof(m_cache)); + Q_memset(m_cache, 0, sizeof(m_cache)); m_cacheIndex = 0; } @@ -285,11 +285,11 @@ bool ObjectDictionary::CheckSize() if (!newEntries) return false; - memset(&newEntries[m_size], 0, sizeof(entry_t) * (newSize - m_size)); + Q_memset(&newEntries[m_size], 0, sizeof(entry_t) * (newSize - m_size)); if (m_entries && m_size) { - memcpy(newEntries, m_entries, sizeof(entry_t) * m_size); + Q_memcpy(newEntries, m_entries, sizeof(entry_t) * m_size); Mem_Free(m_entries); } diff --git a/rehlds/common/SteamAppStartUp.cpp b/rehlds/common/SteamAppStartUp.cpp index 87cdc55..7f13f4b 100644 --- a/rehlds/common/SteamAppStartUp.cpp +++ b/rehlds/common/SteamAppStartUp.cpp @@ -55,7 +55,7 @@ void LaunchSelfViaSteam(const char *params) ::GetModuleFileName((HINSTANCE)GetModuleHandle(NULL), appPath, sizeof(appPath)); // strip out the exe name - char *slash = strrchr(appPath, '\\'); + char *slash = Q_strrchr(appPath, '\\'); if (slash) { *slash = '\0'; @@ -66,9 +66,9 @@ void LaunchSelfViaSteam(const char *params) if (ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER, "Software\\Valve\\Steam", &hKey)) { DWORD dwType = REG_SZ; - DWORD dwSize = static_cast( strlen(appPath) + 1 ); + DWORD dwSize = static_cast(Q_strlen(appPath) + 1); RegSetValueEx(hKey, "TempAppPath", NULL, dwType, (LPBYTE)appPath, dwSize); - dwSize = static_cast( strlen(params) + 1 ); + dwSize = static_cast(Q_strlen(params) + 1); RegSetValueEx(hKey, "TempAppCmdLine", NULL, dwType, (LPBYTE)params, dwSize); // clear out the appID (since we don't know it yet) dwType = REG_DWORD; @@ -93,38 +93,38 @@ void LaunchSelfViaSteam(const char *params) if (::GetCurrentDirectoryA(sizeof(dir), dir)) { - char *slash = strrchr(dir, '\\'); + char *slash = Q_strrchr(dir, '\\'); while (slash) { // see if steam_dev.exe is in the directory first - slash[1] = 0; - strcat(slash, "steam_dev.exe"); + slash[1] = '\0'; + Q_strcat(slash, "steam_dev.exe"); FILE *f = fopen(dir, "rb"); if (f) { // found it fclose(f); - strcpy(steamExe, dir); + Q_strcpy(steamExe, dir); break; } // see if steam.exe is in the directory - slash[1] = 0; - strcat(slash, "steam.exe"); + slash[1] = '\0'; + Q_strcat(slash, "steam.exe"); f = fopen(dir, "rb"); if (f) { // found it fclose(f); - strcpy(steamExe, dir); + Q_strcpy(steamExe, dir); break; } // kill the string at the slash - slash[0] = 0; + slash[0] = '\0'; // move to the previous slash - slash = strrchr(dir, '\\'); + slash = Q_strrchr(dir, '\\'); } } @@ -158,11 +158,11 @@ void LaunchSelfViaSteam(const char *params) } // change to the steam directory - strcpy(dir, steamExe); - char *delimiter = strrchr(dir, '\\'); + Q_strcpy(dir, steamExe); + char *delimiter = Q_strrchr(dir, '\\'); if (delimiter) { - *delimiter = 0; + *delimiter = '\0'; _chdir(dir); } @@ -176,12 +176,12 @@ void LaunchSelfViaSteam(const char *params) bool ShouldLaunchAppViaSteam(const char *lpCmdLine, const char *steamFilesystemDllName, const char *stdioFilesystemDllName) { // see if steam is on the command line - const char *steamStr = strstr(lpCmdLine, STEAM_PARM); + const char *steamStr = Q_strstr(lpCmdLine, STEAM_PARM); // check the character following it is a whitespace or null if (steamStr) { - const char *postChar = steamStr + strlen(STEAM_PARM); + const char *postChar = steamStr + Q_strlen(STEAM_PARM); if (*postChar == 0 || isspace(*postChar)) { // we're running under steam already, let the app continue diff --git a/rehlds/common/TextConsoleUnix.cpp b/rehlds/common/TextConsoleUnix.cpp index b9dcbc6..32671ae 100644 --- a/rehlds/common/TextConsoleUnix.cpp +++ b/rehlds/common/TextConsoleUnix.cpp @@ -86,7 +86,7 @@ bool CTextConsoleUnix::Init(IBaseSystem *system) tcgetattr(STDIN_FILENO, &termStored); - memcpy(&termNew, &termStored, sizeof(struct termios)); + Q_memcpy(&termNew, &termStored, sizeof(struct termios)); // Disable canonical mode, and set buffer size to 1 byte termNew.c_lflag &= (~ICANON); diff --git a/rehlds/common/TextConsoleWin32.cpp b/rehlds/common/TextConsoleWin32.cpp index 16893b1..aeaefb3 100644 --- a/rehlds/common/TextConsoleWin32.cpp +++ b/rehlds/common/TextConsoleWin32.cpp @@ -219,9 +219,9 @@ void CTextConsoleWin32::PrintRaw(char *pszMsg, int nChars) return; WideCharToMultiByte(CP_OEMCP, 0, unicodeStr, -1, outputStr, nLength, NULL, NULL); - WriteFile(houtput, outputStr, nChars ? nChars : strlen(outputStr), NULL, NULL); + WriteFile(houtput, outputStr, nChars ? nChars : Q_strlen(outputStr), NULL, NULL); #else - WriteFile(houtput, pszMsg, nChars ? nChars : strlen(pszMsg), NULL, NULL); + WriteFile(houtput, pszMsg, nChars ? nChars : Q_strlen(pszMsg), NULL, NULL); #endif } @@ -247,7 +247,7 @@ int CTextConsoleWin32::GetWidth() void CTextConsoleWin32::SetStatusLine(char *pszStatus) { - strncpy(statusline, pszStatus, sizeof(statusline) - 1); + Q_strncpy(statusline, pszStatus, sizeof(statusline) - 1); statusline[sizeof(statusline) - 2] = '\0'; UpdateStatus(); } diff --git a/rehlds/common/TokenLine.cpp b/rehlds/common/TokenLine.cpp index f893b09..7f88555 100644 --- a/rehlds/common/TokenLine.cpp +++ b/rehlds/common/TokenLine.cpp @@ -2,9 +2,9 @@ TokenLine::TokenLine() { - memset(m_token, 0, sizeof(m_token)); - memset(m_fullLine, 0, sizeof(m_fullLine)); - memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer)); + Q_memset(m_token, 0, sizeof(m_token)); + Q_memset(m_fullLine, 0, sizeof(m_fullLine)); + Q_memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer)); m_tokenNumber = 0; } @@ -23,10 +23,10 @@ bool TokenLine::SetLine(const char *newLine) { m_tokenNumber = 0; - if (!newLine || (strlen(newLine) >= (MAX_LINE_CHARS - 1))) + if (!newLine || (Q_strlen(newLine) >= (MAX_LINE_CHARS - 1))) { - memset(m_fullLine, 0, sizeof(m_fullLine)); - memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer)); + Q_memset(m_fullLine, 0, sizeof(m_fullLine)); + Q_memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer)); return false; } @@ -95,7 +95,7 @@ char *TokenLine::CheckToken(char *parm) if (!m_token[i]) continue; - if (!strcmp(parm, m_token[i])) + if (!Q_strcmp(parm, m_token[i])) { char *ret = m_token[i + 1]; diff --git a/rehlds/common/commandline.cpp b/rehlds/common/commandline.cpp index 04b810a..1b1a05e 100644 --- a/rehlds/common/commandline.cpp +++ b/rehlds/common/commandline.cpp @@ -52,8 +52,8 @@ char *CopyString(const char *src) if (!src) return nullptr; - char *out = (char *)new char[strlen(src) + 1]; - strcpy(out, src); + char *out = (char *)new char[Q_strlen(src) + 1]; + Q_strcpy(out, src); return out; } @@ -65,21 +65,21 @@ void CCommandLine::CreateCmdLine(int argc, const char *argv[]) for (int i = 0; i < argc; ++i) { - if (strchr(argv[i], ' ')) + if (Q_strchr(argv[i], ' ')) { - strncat(cmdline, "\"", MAX_CHARS); - strncat(cmdline, argv[i], MAX_CHARS); - strncat(cmdline, "\"", MAX_CHARS); + Q_strlcat(cmdline, "\""); + Q_strlcat(cmdline, argv[i]); + Q_strlcat(cmdline, "\""); } else { - strncat(cmdline, argv[i], MAX_CHARS); + Q_strlcat(cmdline, argv[i]); } - strncat(cmdline, " ", MAX_CHARS); + Q_strlcat(cmdline, " "); } - cmdline[strlen(cmdline)] = '\0'; + cmdline[Q_strlen(cmdline)] = '\0'; CreateCmdLine(cmdline); } @@ -184,9 +184,9 @@ void CCommandLine::CreateCmdLine(const char *commandline) *pDst = '\0'; - int len = strlen(szFull) + 1; + int len = Q_strlen(szFull) + 1; m_pszCmdLine = new char[len]; - memcpy(m_pszCmdLine, szFull, len); + Q_memcpy(m_pszCmdLine, szFull, len); } // Purpose: Remove specified string ( and any args attached to it ) from command line @@ -207,8 +207,8 @@ void CCommandLine::RemoveParm(const char *pszParm) p = m_pszCmdLine; while (*p) { - curlen = strlen(p); - found = strstr(p, pszParm); + curlen = Q_strlen(p); + found = Q_strstr(p, pszParm); if (!found) break; @@ -223,21 +223,21 @@ void CCommandLine::RemoveParm(const char *pszParm) // # of characters after this param. n = curlen - (pnextparam - p); - memcpy(found, pnextparam, n); + Q_memcpy(found, pnextparam, n); found[n] = '\0'; } else { // Clear out rest of string. n = pnextparam - found; - memset(found, 0, n); + Q_memset(found, 0, n); } } // Strip and trailing ' ' characters left over. while (1) { - int curpos = strlen(m_pszCmdLine); + int curpos = Q_strlen(m_pszCmdLine); if (curpos == 0 || m_pszCmdLine[ curpos - 1 ] != ' ') break; @@ -252,11 +252,11 @@ void CCommandLine::AppendParm(const char *pszParm, const char *pszValues) char *pCmdString; // Parameter. - nNewLength = strlen(pszParm); + nNewLength = Q_strlen(pszParm); // Values + leading space character. if (pszValues) - nNewLength += strlen(pszValues) + 1; + nNewLength += Q_strlen(pszValues) + 1; // Terminal 0; nNewLength++; @@ -264,11 +264,11 @@ void CCommandLine::AppendParm(const char *pszParm, const char *pszValues) if (!m_pszCmdLine) { m_pszCmdLine = new char[ nNewLength ]; - strcpy(m_pszCmdLine, pszParm); + Q_strcpy(m_pszCmdLine, pszParm); if (pszValues) { - strcat(m_pszCmdLine, " "); - strcat(m_pszCmdLine, pszValues); + Q_strcat(m_pszCmdLine, " "); + Q_strcat(m_pszCmdLine, pszValues); } return; @@ -277,19 +277,19 @@ void CCommandLine::AppendParm(const char *pszParm, const char *pszValues) // Remove any remnants from the current Cmd Line. RemoveParm(pszParm); - nNewLength += strlen(m_pszCmdLine) + 1 + 1; + nNewLength += Q_strlen(m_pszCmdLine) + 1 + 1; pCmdString = new char[ nNewLength ]; - memset(pCmdString, 0, nNewLength); + Q_memset(pCmdString, 0, nNewLength); - strcpy(pCmdString, m_pszCmdLine); // Copy old command line. - strcat(pCmdString, " "); // Put in a space - strcat(pCmdString, pszParm); + Q_strcpy(pCmdString, m_pszCmdLine); // Copy old command line. + Q_strcat(pCmdString, " "); // Put in a space + Q_strcat(pCmdString, pszParm); if (pszValues) { - strcat(pCmdString, " "); - strcat(pCmdString, pszValues); + Q_strcat(pCmdString, " "); + Q_strcat(pCmdString, pszValues); } // Kill off the old one @@ -308,7 +308,7 @@ void CCommandLine::SetParm(const char *pszParm, const char *pszValues) void CCommandLine::SetParm(const char *pszParm, int iValue) { char buf[64]; - _snprintf(buf, sizeof(buf), "%d", iValue); + Q_snprintf(buf, sizeof(buf), "%d", iValue); SetParm(pszParm, buf); } @@ -323,7 +323,7 @@ const char *CCommandLine::CheckParm(const char *psz, char **ppszValue) const if (ppszValue) *ppszValue = nullptr; - char *pret = strstr(m_pszCmdLine, psz); + char *pret = Q_strstr(m_pszCmdLine, psz); if (!pret || !ppszValue) return pret; @@ -345,7 +345,7 @@ const char *CCommandLine::CheckParm(const char *psz, char **ppszValue) const sz[i] = '\0'; *ppszValue = sz; - + return pret; } diff --git a/rehlds/common/textconsole.cpp b/rehlds/common/textconsole.cpp index d9603a7..45d13d7 100644 --- a/rehlds/common/textconsole.cpp +++ b/rehlds/common/textconsole.cpp @@ -33,14 +33,14 @@ bool CTextConsole::Init(IBaseSystem *system) // NULL or a valid base system interface m_System = system; - memset(m_szConsoleText, 0, sizeof(m_szConsoleText)); + Q_memset(m_szConsoleText, 0, sizeof(m_szConsoleText)); m_nConsoleTextLen = 0; m_nCursorPosition = 0; - memset(m_szSavedConsoleText, 0, sizeof(m_szSavedConsoleText)); + Q_memset(m_szSavedConsoleText, 0, sizeof(m_szSavedConsoleText)); m_nSavedConsoleTextLen = 0; - memset(m_aszLineBuffer, 0, sizeof(m_aszLineBuffer)); + Q_memset(m_aszLineBuffer, 0, sizeof(m_aszLineBuffer)); m_nTotalLines = 0; m_nInputLine = 0; m_nBrowseLine = 0; @@ -110,9 +110,9 @@ int CTextConsole::ReceiveNewline() m_nCursorPosition = 0; // cache line in buffer, but only if it's not a duplicate of the previous line - if ((m_nInputLine == 0) || (strcmp(m_aszLineBuffer[ m_nInputLine - 1 ], m_szConsoleText))) + if ((m_nInputLine == 0) || (Q_strcmp(m_aszLineBuffer[ m_nInputLine - 1 ], m_szConsoleText))) { - strncpy(m_aszLineBuffer[ m_nInputLine ], m_szConsoleText, MAX_CONSOLE_TEXTLEN); + Q_strncpy(m_aszLineBuffer[ m_nInputLine ], m_szConsoleText, MAX_CONSOLE_TEXTLEN); m_nInputLine++; if (m_nInputLine > m_nTotalLines) @@ -176,16 +176,16 @@ void CTextConsole::ReceiveTab() if (matches.CountElements() == 1) { char *pszCmdName = (char *)matches.GetFirst(); - char *pszRest = pszCmdName + strlen(m_szConsoleText); + char *pszRest = pszCmdName + Q_strlen(m_szConsoleText); if (pszRest) { Echo(pszRest); - strcat(m_szConsoleText, pszRest); - m_nConsoleTextLen += strlen(pszRest); + Q_strlcat(m_szConsoleText, pszRest); + m_nConsoleTextLen += Q_strlen(pszRest); Echo(" "); - strcat(m_szConsoleText, " "); + Q_strlcat(m_szConsoleText, " "); m_nConsoleTextLen++; } } @@ -199,17 +199,17 @@ void CTextConsole::ReceiveTab() char szFormatCmd[256]; char *pszSmallestCmd; char *pszCurrentCmd = (char *)matches.GetFirst(); - nSmallestCmd = strlen(pszCurrentCmd); + nSmallestCmd = Q_strlen(pszCurrentCmd); pszSmallestCmd = pszCurrentCmd; while (pszCurrentCmd) { - if ((int)strlen(pszCurrentCmd) > nLongestCmd) + if ((int)Q_strlen(pszCurrentCmd) > nLongestCmd) { - nLongestCmd = strlen(pszCurrentCmd); + nLongestCmd = Q_strlen(pszCurrentCmd); } - if ((int)strlen(pszCurrentCmd) < nSmallestCmd) + if ((int)Q_strlen(pszCurrentCmd) < nSmallestCmd) { - nSmallestCmd = strlen(pszCurrentCmd); + nSmallestCmd = Q_strlen(pszCurrentCmd); pszSmallestCmd = pszCurrentCmd; } pszCurrentCmd = (char *)matches.GetNext(); @@ -231,7 +231,7 @@ void CTextConsole::ReceiveTab() nCurrentColumn = 1; } - _snprintf(szFormatCmd, sizeof(szFormatCmd), "%-*s ", nLongestCmd, pszCurrentCmd); + Q_snprintf(szFormatCmd, sizeof(szFormatCmd), "%-*s ", nLongestCmd, pszCurrentCmd); Echo(szFormatCmd); for (char *pCur = pszCurrentCmd, *pCommon = szCommonCmd; (*pCur && *pCommon); pCur++, pCommon++) { @@ -307,7 +307,7 @@ void CTextConsole::ReceiveUpArrow() if (m_nConsoleTextLen > 0) { // Save off current text - strncpy(m_szSavedConsoleText, m_szConsoleText, m_nConsoleTextLen); + Q_strncpy(m_szSavedConsoleText, m_szConsoleText, m_nConsoleTextLen); // No terminator, it's a raw buffer we always know the length of } @@ -329,9 +329,9 @@ void CTextConsole::ReceiveUpArrow() // copy buffered line Echo(m_aszLineBuffer[ m_nBrowseLine ]); - strncpy(m_szConsoleText, m_aszLineBuffer[ m_nBrowseLine ], MAX_CONSOLE_TEXTLEN); + Q_strncpy(m_szConsoleText, m_aszLineBuffer[ m_nBrowseLine ], MAX_CONSOLE_TEXTLEN); - m_nConsoleTextLen = strlen(m_aszLineBuffer[ m_nBrowseLine ]); + m_nConsoleTextLen = Q_strlen(m_aszLineBuffer[ m_nBrowseLine ]); m_nCursorPosition = m_nConsoleTextLen; } @@ -354,7 +354,7 @@ void CTextConsole::ReceiveDownArrow() if (m_nSavedConsoleTextLen > 0) { // Restore current text - strncpy(m_szConsoleText, m_szSavedConsoleText, m_nSavedConsoleTextLen); + Q_strncpy(m_szConsoleText, m_szSavedConsoleText, m_nSavedConsoleTextLen); // No terminator, it's a raw buffer we always know the length of Echo(m_szConsoleText, m_nSavedConsoleTextLen); @@ -366,8 +366,8 @@ void CTextConsole::ReceiveDownArrow() { // copy buffered line Echo(m_aszLineBuffer[ m_nBrowseLine ]); - strncpy(m_szConsoleText, m_aszLineBuffer[ m_nBrowseLine ], MAX_CONSOLE_TEXTLEN); - m_nConsoleTextLen = strlen(m_aszLineBuffer[ m_nBrowseLine ]); + Q_strncpy(m_szConsoleText, m_aszLineBuffer[ m_nBrowseLine ], MAX_CONSOLE_TEXTLEN); + m_nConsoleTextLen = Q_strlen(m_aszLineBuffer[ m_nBrowseLine ]); } m_nCursorPosition = m_nConsoleTextLen; diff --git a/rehlds/dedicated/src/conproc.cpp b/rehlds/dedicated/src/conproc.cpp index a71ded6..c3d6d62 100644 --- a/rehlds/dedicated/src/conproc.cpp +++ b/rehlds/dedicated/src/conproc.cpp @@ -280,17 +280,17 @@ void InitConProc() // give external front ends a chance to hook into the console if (CommandLine()->CheckParm("-HFILE", &p) && p) { - hFile = (HANDLE)atoi(p); + hFile = (HANDLE)Q_atoi(p); } if (CommandLine()->CheckParm("-HPARENT", &p) && p) { - heventParent = (HANDLE)atoi(p); + heventParent = (HANDLE)Q_atoi(p); } if (CommandLine()->CheckParm("-HCHILD", &p) && p) { - heventChild = (HANDLE)atoi(p); + heventChild = (HANDLE)Q_atoi(p); } // ignore if we don't have all the events. @@ -327,7 +327,7 @@ void InitConProc() if (CommandLine()->CheckParm("-conheight", &p) && p) { - WantHeight = atoi(p); + WantHeight = Q_atoi(p); } // Force 80 character width, at least 25 character height diff --git a/rehlds/dedicated/src/sys_ded.cpp b/rehlds/dedicated/src/sys_ded.cpp index 21c32ec..df0cfea 100644 --- a/rehlds/dedicated/src/sys_ded.cpp +++ b/rehlds/dedicated/src/sys_ded.cpp @@ -55,7 +55,7 @@ void Sys_Printf(char *fmt, ...) char szText[1024]; va_start(argptr, fmt); - _vsnprintf(szText, sizeof(szText), fmt, argptr); + Q_vsnprintf(szText, sizeof(szText), fmt, argptr); va_end(argptr); // Get Current text and append it. @@ -80,7 +80,7 @@ void ProcessConsoleInput() if (inputLine) { char szBuf[256]; - _snprintf(szBuf, sizeof(szBuf), "%s\n", inputLine); + Q_snprintf(szBuf, sizeof(szBuf), "%s\n", inputLine); engineAPI->AddConsoleText(szBuf); } } @@ -134,11 +134,11 @@ int RunEngine() const char *steamPath = getenv("SteamInstallPath"); if (steamPath) { // put the config dir directly under steam - _snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath); + Q_snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath); } else { // we're not running steam, so just put the config dir under the platform - strncpy(szConfigDir, "platform/config", sizeof(szConfigDir)); + Q_strlcpy(szConfigDir, "platform/config"); } }*/ #endif // VGUI diff --git a/rehlds/dedicated/src/sys_linux.cpp b/rehlds/dedicated/src/sys_linux.cpp index 9f9af94..22b5d67 100644 --- a/rehlds/dedicated/src/sys_linux.cpp +++ b/rehlds/dedicated/src/sys_linux.cpp @@ -152,7 +152,7 @@ void Sys_InitPingboost() char *pPingType; if (CommandLine()->CheckParm("-pingboost", &pPingType) && pPingType) { - int type = atoi(pPingType); + int type = Q_atoi(pPingType); switch (type) { case 1: signal(SIGALRM, alarmFunc); @@ -195,7 +195,7 @@ void Sys_WriteProcessIdFile() bool CSys::GetExecutableName(char *out) { - strcpy(out, g_szEXEName); + Q_strcpy(out, g_szEXEName); return true; } @@ -222,10 +222,10 @@ long CSys::LoadLibrary(char *lib) if (!getcwd(cwd, sizeof(cwd))) ErrorMessage(1, "Sys_LoadLibrary: Couldn't determine current directory."); - if (cwd[strlen(cwd) - 1] == '/') - cwd[strlen(cwd) - 1] = '\0'; + if (cwd[Q_strlen(cwd) - 1] == '/') + cwd[Q_strlen(cwd) - 1] = '\0'; - _snprintf(absolute_lib, sizeof(absolute_lib), "%s/%s", cwd, lib); + Q_snprintf(absolute_lib, sizeof(absolute_lib), "%s/%s", cwd, lib); void *hDll = dlopen(absolute_lib, RTLD_NOW); if (!hDll) @@ -272,7 +272,7 @@ void CSys::Printf(char *fmt, ...) char szText[1024]; va_start(argptr, fmt); - _vsnprintf(szText, sizeof(szText), fmt, argptr); + Q_vsnprintf(szText, sizeof(szText), fmt, argptr); va_end(argptr); // Get Current text and append it. @@ -288,7 +288,7 @@ char* BuildCmdLine(int argc, char **argv) for (int i = 1; i < argc; i++) { - len += strlen(argv[i]) + 1; + len += Q_strlen(argv[i]) + 1; } if (len > MAX_LINUX_CMDLINE) @@ -301,10 +301,10 @@ char* BuildCmdLine(int argc, char **argv) for (int i = 1; i < argc; i++) { if (i > 1) { - strcat(linuxCmdline, " "); + Q_strlcat(linuxCmdline, " "); } - strcat(linuxCmdline, argv[i]); + Q_strlcat(linuxCmdline, argv[i]); } return linuxCmdline; @@ -321,7 +321,7 @@ void Sys_PrepareConsoleInput() int main(int argc, char *argv[]) { - _snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]); + Q_snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]); char* cmdline = BuildCmdLine(argc, argv); StartServer(cmdline); diff --git a/rehlds/dedicated/src/sys_window.cpp b/rehlds/dedicated/src/sys_window.cpp index 999efc1..4cec9a2 100644 --- a/rehlds/dedicated/src/sys_window.cpp +++ b/rehlds/dedicated/src/sys_window.cpp @@ -113,7 +113,7 @@ void CSys::UpdateStatus(int force) } tLast = tCurrent; - _snprintf(szStatus, sizeof(szStatus), "%.1f fps %2i/%2i on %16s", fps, n, nMax, szMap); + Q_snprintf(szStatus, sizeof(szStatus), "%.1f fps %2i/%2i on %16s", fps, n, nMax, szMap); console.SetStatusLine(szStatus); console.UpdateStatus(); @@ -178,7 +178,7 @@ void CSys::Printf(char *fmt, ...) char szText[1024]; va_start(argptr, fmt); - _vsnprintf(szText, sizeof(szText), fmt, argptr); + Q_vsnprintf(szText, sizeof(szText), fmt, argptr); va_end(argptr); // Get Current text and append it. diff --git a/rehlds/dedicated/src/vgui/vguihelpers.cpp b/rehlds/dedicated/src/vgui/vguihelpers.cpp index facd66a..6739231 100644 --- a/rehlds/dedicated/src/vgui/vguihelpers.cpp +++ b/rehlds/dedicated/src/vgui/vguihelpers.cpp @@ -70,12 +70,12 @@ int StartVGUI() if (steamPath) { // put the config dir directly under steam - _snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath); + Q_snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath); } else { // we're not running steam, so just put the config dir under the platform - strncpy(szConfigDir, "platform/config", sizeof(szConfigDir)); + Q_strlcpy(szConfigDir, "platform/config"); } mkdir(szConfigDir); diff --git a/rehlds/engine/info.cpp b/rehlds/engine/info.cpp index 3a0ec82..7d5f19f 100644 --- a/rehlds/engine/info.cpp +++ b/rehlds/engine/info.cpp @@ -170,7 +170,7 @@ void Info_RemoveKey(char *s, const char *key) // Compare keys if (!Q_strncmp(key, pkey, cmpsize)) { - strcpy_safe(start, s); // remove this part + Q_strcpy_s(start, s); // remove this part s = start; // continue searching } } @@ -235,7 +235,7 @@ void Info_RemovePrefixedKeys(char *s, const char prefix) if (pkey[0] == prefix) { - strcpy_safe(start, s); // remove this part + Q_strcpy_s(start, s); // remove this part s = start; // continue searching } } diff --git a/rehlds/hookers/HLTV/Core/DeltaEx.cpp b/rehlds/hookers/HLTV/Core/DeltaEx.cpp index d93df91..4630e76 100644 --- a/rehlds/hookers/HLTV/Core/DeltaEx.cpp +++ b/rehlds/hookers/HLTV/Core/DeltaEx.cpp @@ -299,7 +299,7 @@ delta_description_t *DELTA_FindField(delta_t *pFields, const char *pszField) { for (int i = 0; i < pFields->fieldCount; i++) { - if (_stricmp(pFields->pdd[i].fieldName, pszField) == 0) { + if (Q_stricmp(pFields->pdd[i].fieldName, pszField) == 0) { return &pFields->pdd[i]; } } @@ -311,7 +311,7 @@ int DELTA_FindFieldIndex(delta_t *pFields, const char *fieldname) { for (int i = 0; i < pFields->fieldCount; i++) { - if (_stricmp(pFields->pdd[i].fieldName, fieldname) == 0) { + if (Q_stricmp(pFields->pdd[i].fieldName, fieldname) == 0) { return i; } } @@ -404,7 +404,7 @@ void DELTA_MarkSendFields(unsigned char *from, unsigned char *to, delta_t *pFiel st2 = (char *)&to[pTest->fieldOffset]; // Not sure why it is case insensitive, but it looks so - if (!(!*st1 && !*st2 || *st1 && *st2 && !_stricmp(st1, st2))) { + if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) { pTest->flags |= FDT_MARK; } break; @@ -424,7 +424,7 @@ void DELTA_SetSendFlagBits(delta_t *pFields, int *bits, int *bytecount) int lastbit = -1; int fieldCount = pFields->fieldCount; - memset(bits, 0, 8); + Q_memset(bits, 0, 8); for (i = fieldCount - 1; i >= 0; i--) { @@ -686,7 +686,7 @@ int DELTA_ParseDelta(BitBuffer *stream, unsigned char *from, unsigned char *to, int startbit; startbit = stream->CurrentBit(); - memset(bits, 0, sizeof(bits)); + Q_memset(bits, 0, sizeof(bits)); nbytes = stream->ReadBits(3); for (i = 0; i < nbytes; i++) { @@ -717,7 +717,7 @@ int DELTA_ParseDelta(BitBuffer *stream, unsigned char *from, unsigned char *to, *(uint32 *)&to[pTest->fieldOffset] = *(uint32 *)&from[pTest->fieldOffset]; break; case DT_STRING: - strcpy((char *)&to[pTest->fieldOffset], (char *)&from[pTest->fieldOffset]); + Q_strcpy((char *)&to[pTest->fieldOffset], (char *)&from[pTest->fieldOffset]); break; default: break; @@ -919,10 +919,10 @@ int DELTA_TestDelta(unsigned char *from, unsigned char *to, delta_t *pFields) st2 = (char *)&to[pTest->fieldOffset]; // Not sure why it is case insensitive, but it looks so - if (!(!*st1 && !*st2 || *st1 && *st2 && !_stricmp(st1, st2))) + if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) { different = true; - length = strlen(st2) * 8; + length = Q_strlen(st2) * 8; pTest->flags |= FDT_MARK; } break; @@ -947,7 +947,7 @@ int DELTA_TestDelta(unsigned char *from, unsigned char *to, delta_t *pFields) void DELTA_AddEncoder(char *name, encoder_t conditionalencode) { delta_encoder_t *delta = (delta_encoder_t *)Mem_ZeroMalloc(sizeof(delta_encoder_t)); - delta->name = _strdup(name); + delta->name = Q_strdup(name); delta->conditionalencode = conditionalencode; delta->next = g_encoders; g_encoders = delta; @@ -972,7 +972,7 @@ encoder_t DELTA_LookupEncoder(char *name) delta_encoder_t *p = g_encoders; while (p) { - if (_stricmp(name, p->name) == 0) { + if (Q_stricmp(name, p->name) == 0) { return p->conditionalencode; } @@ -1041,7 +1041,7 @@ delta_t *DELTA_BuildFromLinks(delta_link_t **pplinks) for (p = *pplinks, pcur = pdesc; p; p = p->next, pcur++) { - memcpy(pcur, p->delta, sizeof(delta_description_t)); + Q_memcpy(pcur, p->delta, sizeof(delta_description_t)); Mem_Free(p->delta); p->delta = nullptr; } @@ -1059,7 +1059,7 @@ int DELTA_FindOffset(int count, delta_definition_t *pdef, char *fieldname) { for (int i = 0; i < count; i++) { - if (_stricmp(fieldname, pdef[i].fieldName) == 0) { + if (Q_stricmp(fieldname, pdef[i].fieldName) == 0) { return pdef[i].fieldOffset; } } @@ -1072,30 +1072,30 @@ bool DELTA_ParseType(delta_description_t *pdelta, char **pstream) // Read the stream till we hit the end while (*pstream = COM_Parse(*pstream), com_token[0] != 0) { - if (!_stricmp(com_token, ",")) + if (!Q_stricmp(com_token, ",")) return true; // end of type description - if (!_stricmp(com_token, "|")) + if (!Q_stricmp(com_token, "|")) continue; // skip | token // Determine field type - if (!_stricmp(com_token, "DT_SIGNED")) + if (!Q_stricmp(com_token, "DT_SIGNED")) pdelta->fieldType |= DT_SIGNED; - else if (!_stricmp(com_token, "DT_BYTE")) + else if (!Q_stricmp(com_token, "DT_BYTE")) pdelta->fieldType |= DT_BYTE; - else if (!_stricmp(com_token, "DT_SHORT")) + else if (!Q_stricmp(com_token, "DT_SHORT")) pdelta->fieldType |= DT_SHORT; - else if (!_stricmp(com_token, "DT_FLOAT")) + else if (!Q_stricmp(com_token, "DT_FLOAT")) pdelta->fieldType |= DT_FLOAT; - else if (!_stricmp(com_token, "DT_INTEGER")) + else if (!Q_stricmp(com_token, "DT_INTEGER")) pdelta->fieldType |= DT_INTEGER; - else if (!_stricmp(com_token, "DT_ANGLE")) + else if (!Q_stricmp(com_token, "DT_ANGLE")) pdelta->fieldType |= DT_ANGLE; - else if (!_stricmp(com_token, "DT_TIMEWINDOW_8")) + else if (!Q_stricmp(com_token, "DT_TIMEWINDOW_8")) pdelta->fieldType |= DT_TIMEWINDOW_8; - else if (!_stricmp(com_token, "DT_TIMEWINDOW_BIG")) + else if (!Q_stricmp(com_token, "DT_TIMEWINDOW_BIG")) pdelta->fieldType |= DT_TIMEWINDOW_BIG; - else if (!_stricmp(com_token, "DT_STRING")) + else if (!Q_stricmp(com_token, "DT_STRING")) pdelta->fieldType |= DT_STRING; else { @@ -1110,9 +1110,9 @@ bool DELTA_ParseType(delta_description_t *pdelta, char **pstream) bool DELTA_ParseField(int count, delta_definition_t *pdefinition, delta_link_t *pField, char **pstream) { bool readpost = false; - if (_stricmp(com_token, "DEFINE_DELTA")) + if (Q_stricmp(com_token, "DEFINE_DELTA")) { - if (_stricmp(com_token, "DEFINE_DELTA_POST") != 0) { + if (Q_stricmp(com_token, "DEFINE_DELTA_POST") != 0) { return false; } @@ -1120,7 +1120,7 @@ bool DELTA_ParseField(int count, delta_definition_t *pdefinition, delta_link_t * } *pstream = COM_Parse(*pstream); - if (_stricmp(com_token, "(")) + if (Q_stricmp(com_token, "(")) { return false; } @@ -1131,8 +1131,7 @@ bool DELTA_ParseField(int count, delta_definition_t *pdefinition, delta_link_t * return false; } - strncpy(pField->delta->fieldName, com_token, sizeof(pField->delta->fieldName) - 1); - pField->delta->fieldName[sizeof(pField->delta->fieldName) - 1] = '\0'; + Q_strlcpy(pField->delta->fieldName, com_token); pField->delta->fieldOffset = DELTA_FindOffset(count, pdefinition, com_token); @@ -1143,16 +1142,16 @@ bool DELTA_ParseField(int count, delta_definition_t *pdefinition, delta_link_t * *pstream = COM_Parse(*pstream); pField->delta->fieldSize = 1; - pField->delta->significant_bits = atoi(com_token); + pField->delta->significant_bits = Q_atoi(com_token); *pstream = COM_Parse(*pstream); *pstream = COM_Parse(*pstream); - pField->delta->premultiply = (float)atof(com_token); + pField->delta->premultiply = (float)Q_atof(com_token); if (readpost) { *pstream = COM_Parse(*pstream); *pstream = COM_Parse(*pstream); - pField->delta->postmultiply = (float)atof(com_token); + pField->delta->postmultiply = (float)Q_atof(com_token); } else { @@ -1160,13 +1159,13 @@ bool DELTA_ParseField(int count, delta_definition_t *pdefinition, delta_link_t * } *pstream = COM_Parse(*pstream); - if (_stricmp(com_token, ")")) + if (Q_stricmp(com_token, ")")) { return false; } *pstream = COM_Parse(*pstream); - if (_stricmp(com_token, ",")) { + if (Q_stricmp(com_token, ",")) { COM_UngetToken(); } @@ -1191,7 +1190,7 @@ void DELTA_AddDefinition(char *name, delta_definition_t *pdef, int numelements) delta_definition_list_t *p = g_defs; while (p) { - if (_stricmp(name, p->ptypename) == 0) { + if (Q_stricmp(name, p->ptypename) == 0) { break; } @@ -1201,7 +1200,7 @@ void DELTA_AddDefinition(char *name, delta_definition_t *pdef, int numelements) if (!p) { p = (delta_definition_list_t *)Mem_ZeroMalloc(sizeof(delta_definition_list_t)); - p->ptypename = _strdup(name); + p->ptypename = Q_strdup(name); p->next = g_defs; g_defs = p; } @@ -1231,7 +1230,7 @@ delta_definition_t *DELTA_FindDefinition(char *name, int *count) delta_definition_list_t *p = g_defs; while (p) { - if (!_stricmp(name, p->ptypename)) + if (!Q_stricmp(name, p->ptypename)) { *count = p->numelements; return p->pdefinition; @@ -1253,7 +1252,7 @@ void DELTA_SkipDescription(char **pstream) return; } } - while (_stricmp(com_token, "}")); + while (Q_stricmp(com_token, "}")); } bool DELTA_ParseOneField(char **ppstream, delta_link_t **pplist, int count, delta_definition_t *pdefinition) @@ -1263,7 +1262,7 @@ bool DELTA_ParseOneField(char **ppstream, delta_link_t **pplist, int count, delt while (true) { - if (!_stricmp(com_token, "}")) + if (!Q_stricmp(com_token, "}")) { COM_UngetToken(); break; @@ -1274,7 +1273,7 @@ bool DELTA_ParseOneField(char **ppstream, delta_link_t **pplist, int count, delt break; } - memset(&link, 0, sizeof(link)); + Q_memset(&link, 0, sizeof(link)); link.delta = (delta_description_t *)Mem_ZeroMalloc(sizeof(delta_description_t)); if (!DELTA_ParseField(count, pdefinition, &link, ppstream)) { return false; @@ -1315,7 +1314,7 @@ bool DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream) break; } - if (_stricmp(com_token, name)) + if (Q_stricmp(com_token, name)) { DELTA_SkipDescription(&pstream); } @@ -1332,10 +1331,9 @@ bool DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream) return false; } - if (_stricmp(com_token, "none")) + if (Q_stricmp(com_token, "none")) { - strncpy(source, com_token, sizeof(source) - 1); - source[sizeof(source) - 1] = '\0'; + Q_strlcpy(source, com_token); // Parse custom encoder function name pstream = COM_Parse(pstream); @@ -1343,8 +1341,7 @@ bool DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream) return false; } - strncpy(encoder, com_token, sizeof(encoder) - 1); - encoder[sizeof(encoder) - 1] = '\0'; + Q_strlcpy(encoder, com_token); } // Parse fields @@ -1355,11 +1352,11 @@ bool DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream) break; } - if (!_stricmp(com_token, "}")) { + if (!Q_stricmp(com_token, "}")) { break; } - if (_stricmp(com_token, "{")) { + if (Q_stricmp(com_token, "{")) { return false; } @@ -1374,8 +1371,7 @@ bool DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream) if (encoder[0]) { - strncpy((*ppdesc)->conditionalencodename, encoder, sizeof((*ppdesc)->conditionalencodename) - 1); - (*ppdesc)->conditionalencodename[sizeof((*ppdesc)->conditionalencodename) - 1] = '\0'; + Q_strlcpy((*ppdesc)->conditionalencodename, encoder1); (*ppdesc)->conditionalencode = nullptr; } @@ -1392,7 +1388,7 @@ void DELTA_RegisterDescription(char *name) delta_registry_t *p = (delta_registry_t *)Mem_ZeroMalloc(sizeof(delta_registry_t)); p->next = g_deltaregistry; g_deltaregistry = p; - p->name = _strdup(name); + p->name = Q_strdup(name); p->pdesc = 0; } @@ -1420,7 +1416,7 @@ delta_t **DELTA_LookupRegistration(char *name) delta_registry_t *delta = g_deltaregistry; while (delta) { - if (_stricmp(delta->name, name) == 0) { + if (Q_stricmp(delta->name, name) == 0) { return &delta->pdesc; } diff --git a/rehlds/public/strtools.h b/rehlds/public/strtools.h index 60784ff..8b414bf 100644 --- a/rehlds/public/strtools.h +++ b/rehlds/public/strtools.h @@ -144,10 +144,11 @@ inline char *_strlwr(char *start) #define Q_fmod fmod #endif // #if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS) -template -char *Q_strlcpy(char (&dest)[N], const char *src) { - Q_strncpy(dest, src, N - 1); - dest[N - 1] = '\0'; +// a safe variant of strcpy that truncates the result to fit in the destination buffer +template +char *Q_strlcpy(char (&dest)[size], const char *src) { + Q_strncpy(dest, src, size - 1); + dest[size - 1] = '\0'; return dest; } @@ -157,19 +158,30 @@ inline char *Q_strnlcpy(char *dest, const char *src, size_t n) { return dest; } -template -size_t Q_strlcat(char (&dest)[N], const char *src) +// safely concatenate two strings. +// a variant of strcat that truncates the result to fit in the destination buffer +template +size_t Q_strlcat(char (&dest)[size], const char *src) { - size_t dstlen = Q_strlen(dest); - size_t size = N - dstlen + 1; + size_t srclen; // Length of source string + size_t dstlen; // Length of destination string - if (!size) { + // Figure out how much room is left + dstlen = Q_strlen(dest); + size_t length = size - dstlen + 1; + + if (!length) { + // No room, return immediately return dstlen; } - size_t srclen = Q_strlen(src); - if (srclen > size) - srclen = size; + // Figure out how much room is needed + srclen = Q_strlen(src); + + // Copy the appropriate amount + if (srclen > length) { + srclen = length; + } Q_memcpy(dest + dstlen, src, srclen); dest[dstlen + srclen] = '\0'; @@ -192,7 +204,7 @@ inline void Q_FixSlashes(char *pname, char separator = CORRECT_PATH_SEPARATOR) } // strcpy that works correctly with overlapping src and dst buffers -inline char *strcpy_safe(char *dst, char *src) { +inline char *Q_strcpy_s(char *dst, char *src) { int len = Q_strlen(src); Q_memmove(dst, src, len + 1); return dst;