get rid of unsafe string functions

minor refactor
This commit is contained in:
s1lentq 2024-09-13 06:43:27 +07:00
parent 3cf66de905
commit 19714af6e6
40 changed files with 268 additions and 365 deletions

View File

@ -332,7 +332,7 @@ void CCSBot::SpawnBot()
TheCSBots()->ValidateMapData(); TheCSBots()->ValidateMapData();
ResetValues(); ResetValues();
Q_strcpy(m_name, STRING(pev->netname)); Q_strlcpy(m_name, STRING(pev->netname));
SetState(&m_buyState); SetState(&m_buyState);
SetTouch(&CCSBot::BotTouch); SetTouch(&CCSBot::BotTouch);

View File

@ -477,14 +477,14 @@ void CCSBot::StartSaveProcess()
void CCSBot::UpdateSaveProcess() void CCSBot::UpdateSaveProcess()
{ {
char filename[256];
char msg[256]; char msg[256];
char cmd[128]; char cmd[128];
GET_GAME_DIR(filename); char gd[64]{};
GET_GAME_DIR(gd);
Q_strcat(filename, "\\"); char filename[MAX_OSPATH];
Q_strcat(filename, TheBots->GetNavMapFilename()); Q_snprintf(filename, sizeof(filename), "%s\\%s", gd, TheBots->GetNavMapFilename());
HintMessageToAllPlayers("Saving..."); HintMessageToAllPlayers("Saving...");
SaveNavigationMap(filename); SaveNavigationMap(filename);

View File

@ -578,14 +578,16 @@ void CCSBotManager::ServerCommand(const char *pcmd)
} }
else if (FStrEq(pcmd, "bot_nav_save")) else if (FStrEq(pcmd, "bot_nav_save"))
{ {
GET_GAME_DIR(buffer); char gd[64]{};
Q_strcat(buffer, "\\"); GET_GAME_DIR(gd);
Q_strcat(buffer, CBotManager::GetNavMapFilename());
if (SaveNavigationMap(buffer)) char filename[MAX_OSPATH];
CONSOLE_ECHO("Navigation map '%s' saved.\n", buffer); Q_snprintf(filename, sizeof(filename), "%s\\%s", gd, CBotManager::GetNavMapFilename());
if (SaveNavigationMap(filename))
CONSOLE_ECHO("Navigation map '%s' saved.\n", filename);
else else
CONSOLE_ECHO("ERROR: Cannot save navigation map '%s'.\n", buffer); CONSOLE_ECHO("ERROR: Cannot save navigation map '%s'.\n", filename);
} }
else if (FStrEq(pcmd, "bot_nav_load")) else if (FStrEq(pcmd, "bot_nav_load"))
{ {

View File

@ -465,7 +465,7 @@ NOXREF int CountTeams()
void ListPlayers(CBasePlayer *current) void ListPlayers(CBasePlayer *current)
{ {
char message[120] = "", cNumber[12]; char message[120]{};
CBaseEntity *pEntity = nullptr; CBaseEntity *pEntity = nullptr;
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player"))) while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
@ -479,12 +479,7 @@ void ListPlayers(CBasePlayer *current)
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev); CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
int iUserID = GETPLAYERUSERID(ENT(pPlayer->pev)); int iUserID = GETPLAYERUSERID(ENT(pPlayer->pev));
Q_sprintf(cNumber, "%d", iUserID); Q_snprintf(message, sizeof(message), "\n%d : %s", iUserID, STRING(pPlayer->pev->netname));
Q_strcpy(message, "\n");
Q_strcat(message, cNumber);
Q_strcat(message, " : ");
Q_strcat(message, STRING(pPlayer->pev->netname));
ClientPrint(current->pev, HUD_PRINTCONSOLE, message); ClientPrint(current->pev, HUD_PRINTCONSOLE, message);
} }
@ -738,8 +733,8 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
pPlayer->m_iJoiningState = SHOWLTEXT; pPlayer->m_iJoiningState = SHOWLTEXT;
static char sName[128]; char sName[128];
Q_strcpy(sName, STRING(pPlayer->pev->netname)); Q_strlcpy(sName, STRING(pPlayer->pev->netname));
for (char *pApersand = sName; pApersand && *pApersand != '\0'; pApersand++) for (char *pApersand = sName; pApersand && *pApersand != '\0'; pApersand++)
{ {
@ -797,12 +792,12 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
{ {
if (CMD_ARGC_() >= 2) if (CMD_ARGC_() >= 2)
{ {
Q_sprintf(szTemp, "%s %s", pcmd, CMD_ARGS()); Q_snprintf(szTemp, sizeof(szTemp), "%s %s", pcmd, CMD_ARGS());
} }
else else
{ {
// Just a one word command, use the first word...sigh // Just a one word command, use the first word...sigh
Q_sprintf(szTemp, "%s", pcmd); Q_snprintf(szTemp, sizeof(szTemp), "%s", pcmd);
} }
p = szTemp; p = szTemp;
@ -967,8 +962,8 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
} }
} }
Q_strcat(text, p); Q_strlcat(text, p);
Q_strcat(text, "\n"); Q_strlcat(text, "\n");
// loop through all players // loop through all players
// Start with the first player. // Start with the first player.
@ -4993,7 +4988,7 @@ void EXT_FUNC UpdateClientData(const edict_t *ent, int sendweapons, struct clien
cd->flSwimTime = pev->flSwimTime; cd->flSwimTime = pev->flSwimTime;
cd->waterjumptime = int(pev->teleport_time); cd->waterjumptime = int(pev->teleport_time);
Q_strcpy(cd->physinfo, ENGINE_GETPHYSINFO(ent)); Q_strlcpy(cd->physinfo, ENGINE_GETPHYSINFO(ent));
cd->maxspeed = pev->maxspeed; cd->maxspeed = pev->maxspeed;
cd->fov = pev->fov; cd->fov = pev->fov;
@ -5204,8 +5199,10 @@ int EXT_FUNC InconsistentFile(const edict_t *pEdict, const char *filename, char
if (!CVAR_GET_FLOAT("mp_consistency")) if (!CVAR_GET_FLOAT("mp_consistency"))
return 0; return 0;
const int BufferLen = 256;
// Default behavior is to kick the player // Default behavior is to kick the player
Q_sprintf(disconnect_message, "Server is enforcing file consistency for %s\n", filename); Q_snprintf(disconnect_message, BufferLen, "Server is enforcing file consistency for %s\n", filename);
// Kick now with specified disconnect message. // Kick now with specified disconnect message.
return 1; return 1;

View File

@ -27,7 +27,7 @@ NOXREF void UTIL_DPrintf(DebugOutputType outputType, char *pszMsg, ...)
{ {
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);
@ -41,7 +41,7 @@ void UTIL_DPrintf(char *pszMsg, ...)
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);
@ -130,7 +130,7 @@ NOXREF void UTIL_BotDPrintf(char *pszMsg, ...)
{ {
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);
@ -146,7 +146,7 @@ void UTIL_CareerDPrintf(char *pszMsg, ...)
{ {
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);
@ -162,7 +162,7 @@ NOXREF void UTIL_TutorDPrintf(char *pszMsg, ...)
{ {
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);
@ -178,7 +178,7 @@ NOXREF void UTIL_StatsDPrintf(char *pszMsg, ...)
{ {
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);
@ -194,7 +194,7 @@ NOXREF void UTIL_HostageDPrintf(char *pszMsg, ...)
{ {
va_list argptr; va_list argptr;
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(theDebugBuffer, pszMsg, argptr); Q_vsnprintf(theDebugBuffer, sizeof(theDebugBuffer), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(theDebugBuffer); SERVER_PRINT(theDebugBuffer);

View File

@ -201,7 +201,7 @@ void ExplosionCreate(const Vector &center, Vector &angles, edict_t *pOwner, int
CBaseEntity *pExplosion = CBaseEntity::Create("env_explosion", center, angles, pOwner); CBaseEntity *pExplosion = CBaseEntity::Create("env_explosion", center, angles, pOwner);
Q_sprintf(buf, "%3d", magnitude); Q_snprintf(buf, sizeof(buf), "%3d", magnitude);
kvd.szKeyName = "iMagnitude"; kvd.szKeyName = "iMagnitude";
kvd.szValue = buf; kvd.szValue = buf;

View File

@ -8,8 +8,8 @@ CGameRules::CGameRules()
m_bBombDropped = FALSE; m_bBombDropped = FALSE;
m_bGameOver = false; m_bGameOver = false;
m_GameDesc = new char[sizeof("Counter-Strike")]; const char *pszGameDesc = AreRunningCZero() ? "Condition Zero" : "Counter-Strike";
Q_strcpy(m_GameDesc, AreRunningCZero() ? "Condition Zero" : "Counter-Strike"); m_GameDesc = CloneString(pszGameDesc);
} }
CGameRules::~CGameRules() CGameRules::~CGameRules()

View File

@ -1009,5 +1009,4 @@ char *GetTeam(int team);
void DestroyMapCycle(mapcycle_t *cycle); void DestroyMapCycle(mapcycle_t *cycle);
int ReloadMapCycleFile(char *filename, mapcycle_t *cycle); int ReloadMapCycleFile(char *filename, mapcycle_t *cycle);
int CountPlayers(); int CountPlayers();
void ExtractCommandString(char *s, char *szCommand);
int GetMapCount(); int GetMapCount();

View File

@ -1605,9 +1605,9 @@ void CHostageImprov::Afraid()
int which = RANDOM_LONG(0, 100) % 3 + 1; int which = RANDOM_LONG(0, 100) % 3 + 1;
Q_sprintf(animInto, "cower_into_%d", which); Q_snprintf(animInto, sizeof(animInto), "cower_into_%d", which);
Q_sprintf(animLoop, "cower_loop_%d", which); Q_snprintf(animLoop, sizeof(animLoop), "cower_loop_%d", which);
Q_sprintf(animExit, "cower_exit_%d", which); Q_snprintf(animExit, sizeof(animExit), "cower_exit_%d", which);
m_animateState.AddSequence(this, animInto); m_animateState.AddSequence(this, animInto);
m_animateState.AddSequence(this, animLoop, RANDOM_FLOAT(3, 10)); m_animateState.AddSequence(this, animLoop, RANDOM_FLOAT(3, 10));

View File

@ -237,7 +237,7 @@ BOOL CItemBattery::MyTouch(CBasePlayer *pPlayer)
pct--; pct--;
char szcharge[64]; char szcharge[64];
Q_sprintf(szcharge, "!HEV_%1dP", pct); Q_snprintf(szcharge, sizeof(szcharge), "!HEV_%1dP", pct);
pPlayer->SetSuitUpdate(szcharge, SUIT_SENTENCE, SUIT_NEXT_IN_30SEC); pPlayer->SetSuitUpdate(szcharge, SUIT_SENTENCE, SUIT_NEXT_IN_30SEC);
return TRUE; return TRUE;

View File

@ -129,11 +129,11 @@ void CEnvLight::KeyValue(KeyValueData *pkvd)
pkvd->fHandled = TRUE; pkvd->fHandled = TRUE;
char szColor[64]; char szColor[64];
Q_sprintf(szColor, "%d", r); Q_snprintf(szColor, sizeof(szColor), "%d", r);
CVAR_SET_STRING("sv_skycolor_r", szColor); CVAR_SET_STRING("sv_skycolor_r", szColor);
Q_sprintf(szColor, "%d", g); Q_snprintf(szColor, sizeof(szColor), "%d", g);
CVAR_SET_STRING("sv_skycolor_g", szColor); CVAR_SET_STRING("sv_skycolor_g", szColor);
Q_sprintf(szColor, "%d", b); Q_snprintf(szColor, sizeof(szColor), "%d", b);
CVAR_SET_STRING("sv_skycolor_b", szColor); CVAR_SET_STRING("sv_skycolor_b", szColor);
} }
else else
@ -147,13 +147,13 @@ void CEnvLight::Spawn()
char szVector[64]; char szVector[64];
UTIL_MakeAimVectors(pev->angles); UTIL_MakeAimVectors(pev->angles);
Q_sprintf(szVector, "%f", gpGlobals->v_forward.x); Q_snprintf(szVector, sizeof(szVector), "%f", gpGlobals->v_forward.x);
CVAR_SET_STRING("sv_skyvec_x", szVector); CVAR_SET_STRING("sv_skyvec_x", szVector);
Q_sprintf(szVector, "%f", gpGlobals->v_forward.y); Q_snprintf(szVector, sizeof(szVector), "%f", gpGlobals->v_forward.y);
CVAR_SET_STRING("sv_skyvec_y", szVector); CVAR_SET_STRING("sv_skyvec_y", szVector);
Q_sprintf(szVector, "%f", gpGlobals->v_forward.z); Q_snprintf(szVector, sizeof(szVector), "%f", gpGlobals->v_forward.z);
CVAR_SET_STRING("sv_skyvec_z", szVector); CVAR_SET_STRING("sv_skyvec_z", szVector);
CLight::Spawn(); CLight::Spawn();

View File

@ -178,15 +178,12 @@ bool CCStrikeGameMgrHelper::GetCanHearPlayer(CBasePlayer* pListener, CBasePlayer
void Broadcast(const char *sentence) void Broadcast(const char *sentence)
{ {
char text[32]; char text[128];
if (!sentence) if (!sentence)
{
return; return;
}
Q_strcpy(text, "%!MRAD_"); Q_snprintf(text, sizeof(text), "%%!MRAD_%s", sentence);
Q_strcat(text, UTIL_VarArgs("%s", sentence));
MESSAGE_BEGIN(MSG_BROADCAST, gmsgSendAudio); MESSAGE_BEGIN(MSG_BROADCAST, gmsgSendAudio);
WRITE_BYTE(0); WRITE_BYTE(0);
@ -507,7 +504,7 @@ CHalfLifeMultiplay::CHalfLifeMultiplay()
char szCommand[256]; char szCommand[256];
ALERT(at_console, "Executing listen server config file\n"); ALERT(at_console, "Executing listen server config file\n");
Q_sprintf(szCommand, "exec %s\n", lservercfgfile); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", lservercfgfile);
SERVER_COMMAND(szCommand); SERVER_COMMAND(szCommand);
} }
} }
@ -4554,12 +4551,7 @@ int ReloadMapCycleFile(char *filename, mapcycle_t *cycle)
if (Q_strlen(pToken) <= 0) if (Q_strlen(pToken) <= 0)
break; break;
#ifdef REGAMEDLL_FIXES Q_strlcpy(szMap, pToken);
Q_strncpy(szMap, pToken, sizeof(szMap) - 1);
szMap[sizeof(szMap) - 1] = '\0';
#else
Q_strcpy(szMap, pToken);
#endif
// Any more tokens on this line? // Any more tokens on this line?
if (SharedTokenWaiting(pFileList)) if (SharedTokenWaiting(pFileList))
@ -4568,7 +4560,7 @@ int ReloadMapCycleFile(char *filename, mapcycle_t *cycle)
if (Q_strlen(pToken) > 0) if (Q_strlen(pToken) > 0)
{ {
hasBuffer = true; hasBuffer = true;
Q_strcpy(szBuffer, pToken); Q_strlcpy(szBuffer, pToken);
} }
} }
@ -4580,7 +4572,7 @@ int ReloadMapCycleFile(char *filename, mapcycle_t *cycle)
item = new mapcycle_item_s; item = new mapcycle_item_s;
Q_strcpy(item->mapname, szMap); Q_strlcpy(item->mapname, szMap);
item->minplayers = 0; item->minplayers = 0;
item->maxplayers = 0; item->maxplayers = 0;
@ -4610,7 +4602,7 @@ int ReloadMapCycleFile(char *filename, mapcycle_t *cycle)
REMOVE_KEY_VALUE(szBuffer, "minplayers"); REMOVE_KEY_VALUE(szBuffer, "minplayers");
REMOVE_KEY_VALUE(szBuffer, "maxplayers"); REMOVE_KEY_VALUE(szBuffer, "maxplayers");
Q_strcpy(item->rulebuffer, szBuffer); Q_strlcpy(item->rulebuffer, szBuffer);
} }
item->next = cycle->items; item->next = cycle->items;
@ -4675,7 +4667,7 @@ int CountPlayers()
} }
// Parse commands/key value pairs to issue right after map xxx command is issued on server level transition // Parse commands/key value pairs to issue right after map xxx command is issued on server level transition
void ExtractCommandString(char *s, char *szCommand) void ExtractCommandString(char *s, char *szCommand, size_t len)
{ {
// Now make rules happen // Now make rules happen
char pkey[512]; char pkey[512];
@ -4744,13 +4736,13 @@ void ExtractCommandString(char *s, char *szCommand)
*c = '\0'; *c = '\0';
Q_strcat(szCommand, pkey); Q_strlcat(szCommand, pkey, len);
if (Q_strlen(value) > 0) if (Q_strlen(value) > 0)
{ {
Q_strcat(szCommand, " "); Q_strlcat(szCommand, " ", len);
Q_strcat(szCommand, value); Q_strlcat(szCommand, value, len);
} }
Q_strcat(szCommand, "\n"); Q_strlcat(szCommand, "\n", len);
/*if (!*s) /*if (!*s)
{ {
@ -4937,10 +4929,10 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(ChangeLevel)()
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
// the absolute default level is de_dust // the absolute default level is de_dust
Q_strcpy(szFirstMapInList, "de_dust"); Q_strlcpy(szFirstMapInList, "de_dust");
#else #else
// the absolute default level is hldm1 // the absolute default level is hldm1
Q_strcpy(szFirstMapInList, "hldm1"); Q_strlcpy(szFirstMapInList, "hldm1");
#endif #endif
int curplayers; int curplayers;
@ -4958,7 +4950,7 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(ChangeLevel)()
// Has the map cycle filename changed? // Has the map cycle filename changed?
if (Q_stricmp(mapcfile, szPreviousMapCycleFile) != 0) if (Q_stricmp(mapcfile, szPreviousMapCycleFile) != 0)
{ {
Q_strcpy(szPreviousMapCycleFile, mapcfile); Q_strlcpy(szPreviousMapCycleFile, mapcfile);
DestroyMapCycle(&mapcycle); DestroyMapCycle(&mapcycle);
@ -4976,8 +4968,8 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(ChangeLevel)()
mapcycle_item_s *item; mapcycle_item_s *item;
// Assume current map // Assume current map
Q_strcpy(szNextMap, STRING(gpGlobals->mapname)); Q_strlcpy(szNextMap, STRING(gpGlobals->mapname));
Q_strcpy(szFirstMapInList, STRING(gpGlobals->mapname)); Q_strlcpy(szFirstMapInList, STRING(gpGlobals->mapname));
// Traverse list // Traverse list
for (item = mapcycle.next_item; item->next != mapcycle.next_item; item = item->next) for (item = mapcycle.next_item; item->next != mapcycle.next_item; item = item->next)
@ -5030,14 +5022,14 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(ChangeLevel)()
mapcycle.next_item = item->next; mapcycle.next_item = item->next;
// Perform logic on current item // Perform logic on current item
Q_strcpy(szNextMap, item->mapname); Q_strlcpy(szNextMap, item->mapname);
ExtractCommandString(item->rulebuffer, szCommands); ExtractCommandString(item->rulebuffer, szCommands, sizeof(szCommands));
Q_strcpy(szRules, item->rulebuffer); Q_strlcpy(szRules, item->rulebuffer);
} }
if (!IS_MAP_VALID(szNextMap)) if (!IS_MAP_VALID(szNextMap))
{ {
Q_strcpy(szNextMap, szFirstMapInList); Q_strlcpy(szNextMap, szFirstMapInList);
} }
m_bGameOver = true; m_bGameOver = true;
@ -5077,17 +5069,7 @@ void CHalfLifeMultiplay::SendMOTDToClient(edict_t *client)
while (pFileList && *pFileList && char_count < MAX_MOTD_LENGTH) while (pFileList && *pFileList && char_count < MAX_MOTD_LENGTH)
{ {
char chunk[MAX_MOTD_CHUNK + 1]; char chunk[MAX_MOTD_CHUNK + 1];
Q_strlcpy(chunk, pFileList);
if (Q_strlen(pFileList) < sizeof(chunk))
{
Q_strcpy(chunk, pFileList);
}
else
{
Q_strncpy(chunk, pFileList, sizeof(chunk) - 1);
// Q_strncpy doesn't always append the null terminator
chunk[sizeof(chunk) - 1] = '\0';
}
char_count += Q_strlen(chunk); char_count += Q_strlen(chunk);

View File

@ -480,14 +480,14 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Observer_SetMode)(int iMode)
{ {
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
m_hObserverTarget = Observer_IsValidTarget( ENTINDEX(m_hObserverTarget->edict()), forcecamera != CAMERA_MODE_SPEC_ANYONE ); m_hObserverTarget = Observer_IsValidTarget( ENTINDEX(m_hObserverTarget->edict()), forcecamera != CAMERA_MODE_SPEC_ANYONE );
#else #else
CBasePlayer *pTarget = m_hObserverTarget; CBasePlayer *pTarget = m_hObserverTarget;
if (pTarget == this if (pTarget == this
|| !pTarget || !pTarget
|| pTarget->has_disconnected || pTarget->has_disconnected
|| pTarget->GetObserverMode() != OBS_NONE || pTarget->GetObserverMode() != OBS_NONE
|| (pTarget->pev->effects & EF_NODRAW) || (pTarget->pev->effects & EF_NODRAW)
|| (forcecamera != CAMERA_MODE_SPEC_ANYONE && pTarget->m_iTeam != m_iTeam)) || (forcecamera != CAMERA_MODE_SPEC_ANYONE && pTarget->m_iTeam != m_iTeam))
m_hObserverTarget = nullptr; m_hObserverTarget = nullptr;
#endif #endif
@ -534,7 +534,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Observer_SetMode)(int iMode)
// print spepctaor mode on client screen // print spepctaor mode on client screen
char modemsg[16]; char modemsg[16];
Q_sprintf(modemsg, "#Spec_Mode%i", pev->iuser1); Q_snprintf(modemsg, sizeof(modemsg), "#Spec_Mode%i", pev->iuser1);
ClientPrint(pev, HUD_PRINTCENTER, modemsg); ClientPrint(pev, HUD_PRINTCENTER, modemsg);
m_iObserverLastMode = iMode; m_iObserverLastMode = iMode;
@ -548,4 +548,4 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Observer_Think)()
Observer_HandleButtons(); Observer_HandleButtons();
Observer_CheckTarget(); Observer_CheckTarget();
Observer_CheckProperties(); Observer_CheckProperties();
} }

View File

@ -2556,11 +2556,19 @@ BOOL CBasePlayer::IsBombGuy()
LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, SetAnimation, (PLAYER_ANIM playerAnim), playerAnim) LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, SetAnimation, (PLAYER_ANIM playerAnim), playerAnim)
int CBasePlayer::GetAnimDesired(const char *szAnim, AnimationType type)
{
const char *refAnim = (type == ANIM_CROUCH && (pev->flags & FL_DUCKING)) ? "crouch_" : "ref_";
char szAnimConstruct[128];
Q_snprintf(szAnimConstruct, sizeof(szAnimConstruct), "%s%s_%s", refAnim, szAnim, m_szAnimExtention);
return LookupSequence(szAnimConstruct);
}
void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
{ {
int animDesired; int animDesired;
float speed; float speed;
char szAnim[64];
int hopSeq; int hopSeq;
int leapSeq; int leapSeq;
@ -2696,16 +2704,17 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
if (m_Activity == m_IdealActivity) if (m_Activity == m_IdealActivity)
return; return;
const char *refAnim;
switch (m_Activity) switch (m_Activity)
{ {
case ACT_RANGE_ATTACK1: Q_strcpy(szAnim, "ref_shoot_"); break; case ACT_RANGE_ATTACK1: refAnim = "shoot"; break;
case ACT_RANGE_ATTACK2: Q_strcpy(szAnim, "ref_shoot2_"); break; case ACT_RANGE_ATTACK2: refAnim = "shoot2"; break;
case ACT_RELOAD: Q_strcpy(szAnim, "ref_reload_"); break; case ACT_RELOAD: refAnim = "reload"; break;
default: Q_strcpy(szAnim, "ref_aim_"); break; default: refAnim = "aim"; break;
} }
Q_strcat(szAnim, m_szAnimExtention); animDesired = GetAnimDesired(refAnim, ANIM_NORMAL);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -2727,13 +2736,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
{ {
m_flLastFired = gpGlobals->time; m_flLastFired = gpGlobals->time;
if (pev->flags & FL_DUCKING) animDesired = GetAnimDesired("shoot", ANIM_CROUCH);
Q_strcpy(szAnim, "crouch_shoot_");
else
Q_strcpy(szAnim, "ref_shoot_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -2748,13 +2751,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
{ {
m_flLastFired = gpGlobals->time; m_flLastFired = gpGlobals->time;
if (pev->flags & FL_DUCKING) animDesired = GetAnimDesired("shoot2", ANIM_CROUCH);
Q_strcpy(szAnim, "crouch_shoot2_");
else
Q_strcpy(szAnim, "ref_shoot2_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -2767,13 +2764,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
} }
case ACT_RELOAD: case ACT_RELOAD:
{ {
if (pev->flags & FL_DUCKING) animDesired = GetAnimDesired("reload", ANIM_CROUCH);
Q_strcpy(szAnim, "crouch_reload_");
else
Q_strcpy(szAnim, "ref_reload_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -2788,13 +2779,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
} }
case ACT_HOLDBOMB: case ACT_HOLDBOMB:
{ {
if (pev->flags & FL_DUCKING) animDesired = GetAnimDesired("aim", ANIM_CROUCH);
Q_strcpy(szAnim, "crouch_aim_");
else
Q_strcpy(szAnim, "ref_aim_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -2811,13 +2796,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
{ {
if (speed <= 135.0f || m_flLastFired + 4.0 >= gpGlobals->time) if (speed <= 135.0f || m_flLastFired + 4.0 >= gpGlobals->time)
{ {
if (pev->flags & FL_DUCKING) animDesired = GetAnimDesired("aim", ANIM_CROUCH);
Q_strcpy(szAnim, "crouch_aim_");
else
Q_strcpy(szAnim, "ref_aim_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -2825,18 +2804,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
} }
else else
{ {
Q_strcpy(szAnim, "run_"); animDesired = GetAnimDesired("run", ANIM_NORMAL);
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
{ {
if (pev->flags & FL_DUCKING) animDesired = GetAnimDesired("aim", ANIM_CROUCH);
Q_strcpy(szAnim, "crouch_aim_");
else
Q_strcpy(szAnim, "ref_aim_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
animDesired = 0; animDesired = 0;
@ -3086,20 +3057,9 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim)
{ {
if (m_Activity != ACT_FLINCH && m_Activity != ACT_LARGE_FLINCH) if (m_Activity != ACT_FLINCH && m_Activity != ACT_LARGE_FLINCH)
{ {
Q_strcpy(szAnim, "run_"); animDesired = GetAnimDesired("run", ANIM_NORMAL);
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
if (animDesired == -1) if (animDesired == -1)
{ animDesired = GetAnimDesired("aim", ANIM_CROUCH);
if (pev->flags & FL_DUCKING)
Q_strcpy(szAnim, "crouch_aim_");
else
Q_strcpy(szAnim, "ref_aim_");
Q_strcat(szAnim, m_szAnimExtention);
animDesired = LookupSequence(szAnim);
}
else else
pev->gaitsequence = animDesired; pev->gaitsequence = animDesired;
@ -5047,8 +5007,7 @@ void CBasePlayer::CheckSuitUpdate()
{ {
// play sentence number // play sentence number
char sentence[MAX_SENTENCE_NAME + 1]; char sentence[MAX_SENTENCE_NAME + 1];
Q_strcpy(sentence, "!"); Q_snprintf(sentence, sizeof(sentence), "!%s", gszallsentencenames[isentence]);
Q_strcat(sentence, gszallsentencenames[isentence]);
EMIT_SOUND_SUIT(ENT(pev), sentence); EMIT_SOUND_SUIT(ENT(pev), sentence);
} }
else else
@ -8074,7 +8033,7 @@ void CBasePlayer::UpdateStatusBar()
char sbuf0[MAX_SBAR_STRING]; char sbuf0[MAX_SBAR_STRING];
Q_memset(newSBarState, 0, sizeof(newSBarState)); Q_memset(newSBarState, 0, sizeof(newSBarState));
Q_strcpy(sbuf0, m_SbarString0); Q_strlcpy(sbuf0, m_SbarString0);
// Find an ID Target // Find an ID Target
TraceResult tr; TraceResult tr;
@ -8104,9 +8063,9 @@ void CBasePlayer::UpdateStatusBar()
if (sameTeam || GetObserverMode() != OBS_NONE) if (sameTeam || GetObserverMode() != OBS_NONE)
{ {
if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE) if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE)
Q_strcpy(sbuf0, "1 %c1: %p2\n2 %h: %i3%%"); Q_strlcpy(sbuf0, "1 %c1: %p2\n2 %h: %i3%%");
else else
Q_strcpy(sbuf0, " "); Q_strlcpy(sbuf0, " ");
newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100); newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100);
@ -8119,9 +8078,9 @@ void CBasePlayer::UpdateStatusBar()
else if (GetObserverMode() == OBS_NONE) else if (GetObserverMode() == OBS_NONE)
{ {
if (playerid.value != PLAYERID_MODE_TEAMONLY && playerid.value != PLAYERID_MODE_OFF) if (playerid.value != PLAYERID_MODE_TEAMONLY && playerid.value != PLAYERID_MODE_OFF)
Q_strcpy(sbuf0, "1 %c1: %p2"); Q_strlcpy(sbuf0, "1 %c1: %p2");
else else
Q_strcpy(sbuf0, " "); Q_strlcpy(sbuf0, " ");
if (!(m_flDisplayHistory & DHF_ENEMY_SEEN)) if (!(m_flDisplayHistory & DHF_ENEMY_SEEN))
{ {
@ -8135,9 +8094,9 @@ void CBasePlayer::UpdateStatusBar()
else if (pEntity->Classify() == CLASS_HUMAN_PASSIVE) else if (pEntity->Classify() == CLASS_HUMAN_PASSIVE)
{ {
if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE) if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE)
Q_strcpy(sbuf0, "1 %c1 %h: %i3%%"); Q_strlcpy(sbuf0, "1 %c1 %h: %i3%%");
else else
Q_strcpy(sbuf0, " "); Q_strlcpy(sbuf0, " ");
newSBarState[SBAR_ID_TARGETTYPE] = SBAR_TARGETTYPE_HOSTAGE; newSBarState[SBAR_ID_TARGETTYPE] = SBAR_TARGETTYPE_HOSTAGE;
newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100); newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100);
@ -8179,7 +8138,7 @@ void CBasePlayer::UpdateStatusBar()
WRITE_STRING(sbuf0); WRITE_STRING(sbuf0);
MESSAGE_END(); MESSAGE_END();
Q_strcpy(m_SbarString0, sbuf0); Q_strlcpy(m_SbarString0, sbuf0);
// make sure everything's resent // make sure everything's resent
bForceResend = true; bForceResend = true;
@ -9370,14 +9329,10 @@ void CBasePlayer::AddAutoBuyData(const char *str)
{ {
if (len > 0) if (len > 0)
{ {
Q_strncat(m_autoBuyString, " ", len); Q_strlcat(m_autoBuyString, " ");
} }
#ifndef REGAMEDLL_FIXES Q_strlcat(m_autoBuyString, str);
Q_strncat(m_autoBuyString, str, sizeof(m_autoBuyString) - Q_strlen(m_autoBuyString));
#else
Q_strncat(m_autoBuyString, str, sizeof(m_autoBuyString) - Q_strlen(m_autoBuyString) - 1);
#endif
} }
} }
@ -9394,9 +9349,7 @@ void CBasePlayer::InitRebuyData(const char *str)
m_rebuyString = nullptr; m_rebuyString = nullptr;
} }
m_rebuyString = new char[Q_strlen(str) + 1]; m_rebuyString = CloneString(str);
Q_strcpy(m_rebuyString, str);
m_rebuyString[Q_strlen(str)] = '\0';
} }
void CBasePlayer::AutoBuy() void CBasePlayer::AutoBuy()
@ -9424,7 +9377,7 @@ void CBasePlayer::AutoBuy()
if (c) if (c)
{ {
Q_strcpy(prioritizedString, c); Q_strlcpy(prioritizedString, c);
PrioritizeAutoBuyString(prioritizedString, m_autoBuyString); PrioritizeAutoBuyString(prioritizedString, m_autoBuyString);
ParseAutoBuyString(prioritizedString, boughtPrimary, boughtSecondary); ParseAutoBuyString(prioritizedString, boughtPrimary, boughtSecondary);
@ -9434,7 +9387,7 @@ void CBasePlayer::AutoBuy()
if (c) if (c)
{ {
Q_strcpy(prioritizedString, c); Q_strlcpy(prioritizedString, c);
PrioritizeAutoBuyString(prioritizedString, m_autoBuyString); PrioritizeAutoBuyString(prioritizedString, m_autoBuyString);
ParseAutoBuyString(prioritizedString, boughtPrimary, boughtSecondary); ParseAutoBuyString(prioritizedString, boughtPrimary, boughtSecondary);
@ -9582,11 +9535,11 @@ const char *CBasePlayer::PickPrimaryCareerTaskWeapon()
CCareerTask *pTask = taskVector[i]; CCareerTask *pTask = taskVector[i];
if (IsPrimaryWeaponId(pTask->GetWeaponId())) if (IsPrimaryWeaponId(pTask->GetWeaponId()))
Q_strncat(buf, WeaponIDToAlias(pTask->GetWeaponId()), sizeof(buf) - Q_strlen(buf) - 1); Q_strlcat(buf, WeaponIDToAlias(pTask->GetWeaponId()));
else else
Q_strncat(buf, GetBuyStringForWeaponClass(pTask->GetWeaponClassId()), sizeof(buf) - Q_strlen(buf) - 1); Q_strlcat(buf, GetBuyStringForWeaponClass(pTask->GetWeaponClassId()));
Q_strncat(buf, " ", sizeof(buf) - Q_strlen(buf) - 1); Q_strlcat(buf, " ");
} }
return buf; return buf;
@ -9657,11 +9610,11 @@ const char *CBasePlayer::PickSecondaryCareerTaskWeapon()
CCareerTask *pTask = taskVector[i]; CCareerTask *pTask = taskVector[i];
if (IsSecondaryWeaponId(pTask->GetWeaponId())) if (IsSecondaryWeaponId(pTask->GetWeaponId()))
Q_strncat(buf, WeaponIDToAlias(pTask->GetWeaponId()), sizeof(buf) - Q_strlen(buf) - 1); Q_strlcat(buf, WeaponIDToAlias(pTask->GetWeaponId()));
else else
Q_strncat(buf, GetBuyStringForWeaponClass(pTask->GetWeaponClassId()), sizeof(buf) - Q_strlen(buf) - 1); Q_strlcat(buf, GetBuyStringForWeaponClass(pTask->GetWeaponClassId()));
Q_strncat(buf, " ", sizeof(buf) - Q_strlen(buf) - 1); Q_strlcat(buf, " ");
} }
return buf; return buf;
@ -9710,7 +9663,7 @@ const char *CBasePlayer::PickGrenadeKillWeaponString()
} }
// PostAutoBuyCommandProcessing - reorders the tokens in autobuyString based on the order of tokens in the priorityString. // PostAutoBuyCommandProcessing - reorders the tokens in autobuyString based on the order of tokens in the priorityString.
void CBasePlayer::PrioritizeAutoBuyString(char *autobuyString, const char *priorityString) void CBasePlayer::PrioritizeAutoBuyString(char (&autobuyString)[MAX_AUTOBUY_LENGTH], const char *priorityString)
{ {
char newString[MAX_AUTOBUY_LENGTH]; char newString[MAX_AUTOBUY_LENGTH];
int newStringPos = 0; int newStringPos = 0;
@ -9783,7 +9736,7 @@ void CBasePlayer::PrioritizeAutoBuyString(char *autobuyString, const char *prior
// terminate the string. Trailing spaces shouldn't matter. // terminate the string. Trailing spaces shouldn't matter.
newString[newStringPos] = '\0'; newString[newStringPos] = '\0';
Q_sprintf(autobuyString, "%s", newString); Q_snprintf(autobuyString, sizeof(autobuyString), "%s", newString);
} }
void CBasePlayer::ParseAutoBuyString(const char *string, bool &boughtPrimary, bool &boughtSecondary) void CBasePlayer::ParseAutoBuyString(const char *string, bool &boughtPrimary, bool &boughtSecondary)

View File

@ -522,7 +522,9 @@ public:
void UpdatePlayerSound(); void UpdatePlayerSound();
void DeathSound(); void DeathSound();
void SetAnimation(PLAYER_ANIM playerAnim); void SetAnimation(PLAYER_ANIM playerAnim);
void SetWeaponAnimType(const char *szExtention) { Q_strcpy(m_szAnimExtention, szExtention); } enum AnimationType { ANIM_NORMAL, ANIM_CROUCH };
int GetAnimDesired(const char *szAnim, AnimationType type);
void SetWeaponAnimType(const char *szExtention) { Q_strlcpy(m_szAnimExtention, szExtention); }
void CheatImpulseCommands(int iImpulse); void CheatImpulseCommands(int iImpulse);
void StartDeathCam(); void StartDeathCam();
void StartObserver(Vector &vecPosition, Vector &vecViewAngle); void StartObserver(Vector &vecPosition, Vector &vecViewAngle);
@ -602,7 +604,7 @@ public:
void AddAutoBuyData(const char *str); void AddAutoBuyData(const char *str);
void AutoBuy(); void AutoBuy();
void ClientCommand(const char *cmd, const char *arg1 = nullptr, const char *arg2 = nullptr, const char *arg3 = nullptr); void ClientCommand(const char *cmd, const char *arg1 = nullptr, const char *arg2 = nullptr, const char *arg3 = nullptr);
void PrioritizeAutoBuyString(char *autobuyString, const char *priorityString); void PrioritizeAutoBuyString(char (&autobuyString)[MAX_AUTOBUY_LENGTH], const char *priorityString);
const char *PickPrimaryCareerTaskWeapon(); const char *PickPrimaryCareerTaskWeapon();
const char *PickSecondaryCareerTaskWeapon(); const char *PickSecondaryCareerTaskWeapon();
const char *PickFlashKillWeaponString(); const char *PickFlashKillWeaponString();

View File

@ -962,8 +962,8 @@ void CGlobalState::EntityAdd(string_t globalname, string_t mapName, GLOBALESTATE
pNewEntity->pNext = m_pList; pNewEntity->pNext = m_pList;
m_pList = pNewEntity; m_pList = pNewEntity;
Q_strcpy(pNewEntity->name, STRING(globalname)); Q_strlcpy(pNewEntity->name, STRING(globalname));
Q_strcpy(pNewEntity->levelName, STRING(mapName)); Q_strlcpy(pNewEntity->levelName, STRING(mapName));
pNewEntity->state = state; pNewEntity->state = state;
m_listCount++; m_listCount++;
@ -1068,7 +1068,7 @@ void CGlobalState::EntityUpdate(string_t globalname, string_t mapname)
globalentity_t *pEnt = Find(globalname); globalentity_t *pEnt = Find(globalname);
if (pEnt) if (pEnt)
{ {
Q_strcpy(pEnt->levelName, STRING(mapname)); Q_strlcpy(pEnt->levelName, STRING(mapname));
} }
} }

View File

@ -10,7 +10,7 @@ NOXREF float GetSkillCvar(char *pName)
float flValue; float flValue;
char szBuffer[64]; char szBuffer[64];
iCount = Q_sprintf(szBuffer, "%s%d", pName, gSkillData.iSkillLevel); iCount = Q_snprintf(szBuffer, sizeof(szBuffer), "%s%d", pName, gSkillData.iSkillLevel);
flValue = CVAR_GET_FLOAT(szBuffer); flValue = CVAR_GET_FLOAT(szBuffer);
if (flValue <= 0.0f) if (flValue <= 0.0f)

View File

@ -1040,11 +1040,10 @@ void USENTENCEG_InitLRU(unsigned char *plru, int count)
// ipick is passed in as the requested sentence ordinal. // ipick is passed in as the requested sentence ordinal.
// ipick 'next' is returned. // ipick 'next' is returned.
// return of -1 indicates an error. // return of -1 indicates an error.
int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int freset) int USENTENCEG_PickSequential(int isentenceg, char (&szfound)[64], int ipick, int freset)
{ {
char *szgroupname; char *szgroupname;
unsigned char count; unsigned char count;
char sznum[12];
if (!fSentencesInit) if (!fSentencesInit)
return -1; return -1;
@ -1061,10 +1060,7 @@ int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int fres
if (ipick >= count) if (ipick >= count)
ipick = count - 1; ipick = count - 1;
Q_strcpy(szfound, "!"); Q_snprintf(szfound, sizeof(szfound), "!%s%d", szgroupname, ipick);
Q_strcat(szfound, szgroupname);
Q_snprintf(sznum, sizeof(sznum), "%d", ipick);
Q_strcat(szfound, sznum);
if (ipick >= count) if (ipick >= count)
{ {
@ -1084,13 +1080,12 @@ int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int fres
// rest of the lru filled with -1. The first integer in the lru is // rest of the lru filled with -1. The first integer in the lru is
// actually the size of the list. Returns ipick, the ordinal // actually the size of the list. Returns ipick, the ordinal
// of the picked sentence within the group. // of the picked sentence within the group.
int USENTENCEG_Pick(int isentenceg, char *szfound) int USENTENCEG_Pick(int isentenceg, char (&szfound)[64])
{ {
char *szgroupname; char *szgroupname;
unsigned char *plru; unsigned char *plru;
unsigned char i; unsigned char i;
unsigned char count; unsigned char count;
char sznum[12];
unsigned char ipick = 0xFF; unsigned char ipick = 0xFF;
BOOL ffound = FALSE; BOOL ffound = FALSE;
@ -1119,11 +1114,7 @@ int USENTENCEG_Pick(int isentenceg, char *szfound)
if (ffound) if (ffound)
{ {
Q_strcpy(szfound, "!"); Q_snprintf(szfound, sizeof(szfound), "!%s%d", szgroupname, ipick);
Q_strcat(szfound, szgroupname);
Q_snprintf(sznum, sizeof(sznum), "%d", ipick);
Q_strcat(szfound, sznum);
return ipick; return ipick;
} }
else else
@ -1168,8 +1159,6 @@ int SENTENCEG_PlayRndI(edict_t *entity, int isentenceg, float volume, float atte
if (!fSentencesInit) if (!fSentencesInit)
return -1; return -1;
name[0] = '\0';
ipick = USENTENCEG_Pick(isentenceg, name); ipick = USENTENCEG_Pick(isentenceg, name);
#ifndef REGAMEDLL_FIXES #ifndef REGAMEDLL_FIXES
@ -1194,8 +1183,6 @@ int SENTENCEG_PlayRndSz(edict_t *entity, const char *szgroupname, float volume,
if (!fSentencesInit) if (!fSentencesInit)
return -1; return -1;
name[0] = '\0';
isentenceg = SENTENCEG_GetIndex(szgroupname); isentenceg = SENTENCEG_GetIndex(szgroupname);
if (isentenceg < 0) if (isentenceg < 0)
{ {
@ -1223,8 +1210,6 @@ int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szgroupname, float v
if (!fSentencesInit) if (!fSentencesInit)
return -1; return -1;
name[0] = '\0';
isentenceg = SENTENCEG_GetIndex(szgroupname); isentenceg = SENTENCEG_GetIndex(szgroupname);
if (isentenceg < 0) if (isentenceg < 0)
return -1; return -1;
@ -1323,7 +1308,7 @@ void SENTENCEG_Init()
ALERT(at_warning, "Sentence %s longer than %d letters\n", pString, MAX_SENTENCE_NAME - 1); ALERT(at_warning, "Sentence %s longer than %d letters\n", pString, MAX_SENTENCE_NAME - 1);
} }
Q_strcpy(gszallsentencenames[gcallsentences++], pString); Q_strlcpy(gszallsentencenames[gcallsentences++], pString);
if (--j <= i) if (--j <= i)
continue; continue;
@ -1354,10 +1339,10 @@ void SENTENCEG_Init()
break; break;
} }
Q_strcpy(rgsentenceg[isentencegs].szgroupname, &(buffer[i])); Q_strlcpy(rgsentenceg[isentencegs].szgroupname, &(buffer[i]));
rgsentenceg[isentencegs].count = 1; rgsentenceg[isentencegs].count = 1;
Q_strcpy(szgroup, &(buffer[i])); Q_strlcpy(szgroup, &(buffer[i]));
continue; continue;
} }
@ -1385,9 +1370,8 @@ void SENTENCEG_Init()
} }
// convert sentence (sample) name to !sentencenum, return !sentencenum // convert sentence (sample) name to !sentencenum, return !sentencenum
int SENTENCEG_Lookup(const char *sample, char *sentencenum) int SENTENCEG_Lookup(const char *sample, char (&sentencenum)[32])
{ {
char sznum[12];
int i; int i;
// this is a sentence name; lookup sentence number // this is a sentence name; lookup sentence number
@ -1398,9 +1382,7 @@ int SENTENCEG_Lookup(const char *sample, char *sentencenum)
{ {
if (sentencenum) if (sentencenum)
{ {
Q_strcpy(sentencenum, "!"); Q_snprintf(sentencenum, sizeof(sentencenum), "!%d", i);
Q_snprintf(sznum, sizeof(sznum), "%d", i);
Q_strcat(sentencenum, sznum);
} }
return i; return i;
@ -1580,7 +1562,7 @@ void TEXTURETYPE_Init()
j = Q_min(j, MAX_TEXTURENAME_LENGHT - 1 + i); j = Q_min(j, MAX_TEXTURENAME_LENGHT - 1 + i);
buffer[j] = '\0'; buffer[j] = '\0';
Q_strcpy(&(grgszTextureName[gcTextures++][0]), &(buffer[i])); Q_strlcpy(grgszTextureName[gcTextures++], &(buffer[i]));
} }
FREE_FILE(pMemFile); FREE_FILE(pMemFile);
@ -1616,7 +1598,7 @@ float TEXTURETYPE_PlaySound(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int
char chTextureType; char chTextureType;
float fvol; float fvol;
float fvolbar; float fvolbar;
char szBuffer[64]; char szBuffer[MAX_TEXTURENAME_LENGHT];
const char *pTextureName; const char *pTextureName;
float rgfl1[3]; float rgfl1[3];
float rgfl2[3]; float rgfl2[3];
@ -1666,8 +1648,7 @@ float TEXTURETYPE_PlaySound(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int
pTextureName++; pTextureName++;
// '}}' // '}}'
Q_strcpy(szBuffer, pTextureName); Q_strlcpy(szBuffer, pTextureName);
szBuffer[MAX_TEXTURENAME_LENGHT - 1] = '\0';
// get texture type // get texture type
chTextureType = TEXTURETYPE_Find(szBuffer); chTextureType = TEXTURETYPE_Find(szBuffer);

View File

@ -170,15 +170,13 @@ public:
BOOL FEnvSoundInRange(entvars_t *pev, entvars_t *pevTarget, float *pflRange); BOOL FEnvSoundInRange(entvars_t *pev, entvars_t *pevTarget, float *pflRange);
void USENTENCEG_InitLRU(unsigned char *plru, int count); void USENTENCEG_InitLRU(unsigned char *plru, int count);
int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int freset);
int USENTENCEG_Pick(int isentenceg, char *szfound);
int SENTENCEG_GetIndex(const char *szgroupname); int SENTENCEG_GetIndex(const char *szgroupname);
int SENTENCEG_PlayRndI(edict_t *entity, int isentenceg, float volume, float attenuation, int flags, int pitch); int SENTENCEG_PlayRndI(edict_t *entity, int isentenceg, float volume, float attenuation, int flags, int pitch);
int SENTENCEG_PlayRndSz(edict_t *entity, const char *szgroupname, float volume, float attenuation, int flags, int pitch); int SENTENCEG_PlayRndSz(edict_t *entity, const char *szgroupname, float volume, float attenuation, int flags, int pitch);
int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szgroupname, float volume, float attenuation, int flags, int pitch, int ipick, int freset); int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szgroupname, float volume, float attenuation, int flags, int pitch, int ipick, int freset);
void SENTENCEG_Stop(edict_t *entity, int isentenceg, int ipick); void SENTENCEG_Stop(edict_t *entity, int isentenceg, int ipick);
void SENTENCEG_Init(); void SENTENCEG_Init();
int SENTENCEG_Lookup(const char *sample, char *sentencenum); int SENTENCEG_Lookup(const char *sample, char (&sentencenum)[32]);
void EMIT_SOUND_DYN(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int flags, int pitch); void EMIT_SOUND_DYN(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int flags, int pitch);
void EMIT_SOUND_SUIT(edict_t *entity, const char *sample); void EMIT_SOUND_SUIT(edict_t *entity, const char *sample);
void EMIT_GROUPID_SUIT(edict_t *entity, int isentenceg); void EMIT_GROUPID_SUIT(edict_t *entity, int isentenceg);

View File

@ -645,7 +645,7 @@ void PlayCDTrack(edict_t *pClient, int iTrack)
CLIENT_COMMAND(pClient, UTIL_VarArgs("mp3 play %s\n", g_szMP3trackFileMap[iTrack])); CLIENT_COMMAND(pClient, UTIL_VarArgs("mp3 play %s\n", g_szMP3trackFileMap[iTrack]));
#else #else
char string[64]; char string[64];
Q_sprintf(string, "cd play %3d\n", iTrack); Q_snprintf(string, sizeof(string), "cd play %3d\n", iTrack);
CLIENT_COMMAND(pClient, string); CLIENT_COMMAND(pClient, string);
#endif #endif
} }
@ -1214,7 +1214,7 @@ void CChangeLevel::KeyValue(KeyValueData *pkvd)
ALERT(at_error, "Map name '%s' too long (32 chars)\n", pkvd->szValue); ALERT(at_error, "Map name '%s' too long (32 chars)\n", pkvd->szValue);
} }
Q_strcpy(m_szMapName, pkvd->szValue); Q_strlcpy(m_szMapName, pkvd->szValue);
pkvd->fHandled = TRUE; pkvd->fHandled = TRUE;
} }
else if (FStrEq(pkvd->szKeyName, "landmark")) else if (FStrEq(pkvd->szKeyName, "landmark"))
@ -1224,7 +1224,7 @@ void CChangeLevel::KeyValue(KeyValueData *pkvd)
ALERT(at_error, "Landmark name '%s' too long (32 chars)\n", pkvd->szValue); ALERT(at_error, "Landmark name '%s' too long (32 chars)\n", pkvd->szValue);
} }
Q_strcpy(m_szLandmarkName, pkvd->szValue); Q_strlcpy(m_szLandmarkName, pkvd->szValue);
pkvd->fHandled = TRUE; pkvd->fHandled = TRUE;
} }
else if (FStrEq(pkvd->szKeyName, "changetarget")) else if (FStrEq(pkvd->szKeyName, "changetarget"))
@ -1356,7 +1356,7 @@ void CChangeLevel::ChangeLevelNow(CBaseEntity *pActivator)
} }
// This object will get removed in the call to CHANGE_LEVEL, copy the params into "safe" memory // This object will get removed in the call to CHANGE_LEVEL, copy the params into "safe" memory
Q_strcpy(st_szNextMap, m_szMapName); Q_strlcpy(st_szNextMap, m_szMapName);
m_hActivator = pActivator; m_hActivator = pActivator;
SUB_UseTargets(pActivator, USE_TOGGLE, 0); SUB_UseTargets(pActivator, USE_TOGGLE, 0);
@ -1369,7 +1369,7 @@ void CChangeLevel::ChangeLevelNow(CBaseEntity *pActivator)
if (!FNullEnt(pentLandmark)) if (!FNullEnt(pentLandmark))
{ {
Q_strcpy(st_szNextSpot, m_szLandmarkName); Q_strlcpy(st_szNextSpot, m_szLandmarkName);
gpGlobals->vecLandmarkOffset = VARS(pentLandmark)->origin; gpGlobals->vecLandmarkOffset = VARS(pentLandmark)->origin;
} }
@ -1415,8 +1415,8 @@ int CChangeLevel::AddTransitionToList(LEVELLIST *pLevelList, int listCount, cons
} }
} }
Q_strcpy(pLevelList[listCount].mapName, pMapName); Q_strlcpy(pLevelList[listCount].mapName, pMapName);
Q_strcpy(pLevelList[listCount].landmarkName, pLandmarkName); Q_strlcpy(pLevelList[listCount].landmarkName, pLandmarkName);
pLevelList[listCount].pentLandmark = pentLandmark; pLevelList[listCount].pentLandmark = pentLandmark;
pLevelList[listCount].vecLandmarkOrigin = VARS(pentLandmark)->origin; pLevelList[listCount].vecLandmarkOrigin = VARS(pentLandmark)->origin;
@ -1591,12 +1591,12 @@ NOXREF void NextLevel()
{ {
gpGlobals->mapname = ALLOC_STRING("start"); gpGlobals->mapname = ALLOC_STRING("start");
pChange = GetClassPtr<CCSChangeLevel>((CChangeLevel *)nullptr); pChange = GetClassPtr<CCSChangeLevel>((CChangeLevel *)nullptr);
Q_strcpy(pChange->m_szMapName, "start"); Q_strlcpy(pChange->m_szMapName, "start");
} }
else else
pChange = GetClassPtr<CCSChangeLevel>((CChangeLevel *)VARS(pent)); pChange = GetClassPtr<CCSChangeLevel>((CChangeLevel *)VARS(pent));
Q_strcpy(st_szNextMap, pChange->m_szMapName); Q_strlcpy(st_szNextMap, pChange->m_szMapName);
g_pGameRules->SetGameOver(); g_pGameRules->SetGameOver();
if (pChange->pev->nextthink < gpGlobals->time) if (pChange->pev->nextthink < gpGlobals->time)

View File

@ -68,12 +68,10 @@ void TutorMessageEvent::AddParameter(char *str)
TutorMessageEventParam *param = new TutorMessageEventParam; TutorMessageEventParam *param = new TutorMessageEventParam;
param->m_next = nullptr; param->m_next = nullptr;
param->m_data = new char[Q_strlen(str) + 1]; param->m_data = CloneString(str);
if (param->m_data) if (param->m_data)
{ {
Q_strcpy(param->m_data, str);
param->m_data[Q_strlen(str)] = '\0';
m_numParameters++; m_numParameters++;
if (m_paramList) if (m_paramList)
@ -101,11 +99,7 @@ char *TutorMessageEvent::GetNextParameter(char *buf, int buflen)
m_numParameters--; m_numParameters--;
m_paramList = param->m_next; m_paramList = param->m_next;
Q_strncpy(buf, param->m_data, buflen); Q_strlcpy(buf, param->m_data, buflen);
#ifdef REGAMEDLL_FIXES
buf[buflen - 1] = '\0';
#endif
delete param; delete param;
return buf; return buf;

View File

@ -213,7 +213,7 @@ void ParseMessageParameters(char *&messageData, TutorMessage *ret)
if (!Q_stricmp(token, "String")) if (!Q_stricmp(token, "String"))
{ {
messageData = SharedParse((char *)messageData); messageData = SharedParse((char *)messageData);
ret->m_text = Q_strdup(SharedGetToken()); ret->m_text = CloneString(SharedGetToken());
} }
else if (!Q_stricmp(token, "Duration")) else if (!Q_stricmp(token, "Duration"))
{ {
@ -832,7 +832,7 @@ TutorMessageEvent *CCSTutor::CreateTutorMessageEvent(TutorMessageID mid, CBaseEn
{ {
numtasks = TheCareerTasks->GetNumRemainingTasks(); numtasks = TheCareerTasks->GetNumRemainingTasks();
} }
Q_sprintf(numLeftStr, "%d", numtasks); Q_snprintf(numLeftStr, sizeof(numLeftStr), "%d", numtasks);
event->AddParameter(numLeftStr); event->AddParameter(numLeftStr);
break; break;
} }
@ -2820,8 +2820,7 @@ void CCSTutor::ConstructRecentDeathsList(TeamName team, char *buf, int buflen, T
if (!buf || !buflen) if (!buf || !buflen)
return; return;
char scratch[32]; int len = 0;
buf[0] = '\0';
for (int i = 1; i <= gpGlobals->maxClients; i++) for (int i = 1; i <= gpGlobals->maxClients; i++)
{ {
@ -2837,10 +2836,7 @@ void CCSTutor::ConstructRecentDeathsList(TeamName team, char *buf, int buflen, T
if (pPlayer->m_iTeam != team) if (pPlayer->m_iTeam != team)
continue; continue;
Q_strcat(buf, " %n"); len += Q_snprintf(&buf[len], buflen - len, " %%n%d\n", i);
Q_sprintf(scratch, "%d\n", i);
Q_strcat(buf, scratch);
m_playerDeathInfo[i].m_event = event; m_playerDeathInfo[i].m_event = event;
} }
} }

View File

@ -690,10 +690,7 @@ void UTIL_Log(const char *fmt, ...)
Q_vsnprintf(string, sizeof(string), fmt, ap); Q_vsnprintf(string, sizeof(string), fmt, ap);
va_end(ap); va_end(ap);
if (Q_strlen(string) < sizeof(string) - 2) Q_strlcat(string, "\n");
Q_strcat(string, "\n");
else
string[Q_strlen(string) - 1] = '\n';
FILE *fp = fopen("regamedll.log", "at"); FILE *fp = fopen("regamedll.log", "at");
if (fp) if (fp)
@ -717,10 +714,7 @@ void UTIL_ServerPrint(const char *fmt, ...)
Q_vsnprintf(string, sizeof(string), fmt, ap); Q_vsnprintf(string, sizeof(string), fmt, ap);
va_end(ap); va_end(ap);
if (Q_strlen(string) < sizeof(string) - 2) Q_strlcat(string, "\n");
Q_strcat(string, "\n");
else
string[Q_strlen(string) - 1] = '\n';
SERVER_PRINT(string); SERVER_PRINT(string);
} }
@ -738,10 +732,7 @@ void UTIL_PrintConsole(edict_t *pEdict, const char *fmt, ...)
Q_vsnprintf(string, sizeof(string), fmt, ap); Q_vsnprintf(string, sizeof(string), fmt, ap);
va_end(ap); va_end(ap);
if (Q_strlen(string) < sizeof(string) - 2) Q_strlcat(string, "\n");
Q_strcat(string, "\n");
else
string[Q_strlen(string) - 1] = '\n';
ClientPrint(pEntity->pev, HUD_PRINTCONSOLE, string); ClientPrint(pEntity->pev, HUD_PRINTCONSOLE, string);
} }
@ -759,10 +750,7 @@ void UTIL_SayText(edict_t *pEdict, const char *fmt, ...)
Q_vsnprintf(string, sizeof(string), fmt, ap); Q_vsnprintf(string, sizeof(string), fmt, ap);
va_end(ap); va_end(ap);
if (Q_strlen(string) < sizeof(string) - 2) Q_strlcat(string, "\n");
Q_strcat(string, "\n");
else
string[Q_strlen(string) - 1] = '\n';
MESSAGE_BEGIN(MSG_ONE, gmsgSayText, nullptr, pEntity->edict()); MESSAGE_BEGIN(MSG_ONE, gmsgSayText, nullptr, pEntity->edict());
WRITE_BYTE(pEntity->entindex()); WRITE_BYTE(pEntity->entindex());
@ -781,28 +769,28 @@ void UTIL_SayTextAll(const char *pText, CBaseEntity *pEntity)
char *UTIL_dtos1(int d) char *UTIL_dtos1(int d)
{ {
static char buf[12]; static char buf[12];
Q_sprintf(buf, "%d", d); Q_snprintf(buf, sizeof(buf), "%d", d);
return buf; return buf;
} }
char *UTIL_dtos2(int d) char *UTIL_dtos2(int d)
{ {
static char buf[12]; static char buf[12];
Q_sprintf(buf, "%d", d); Q_snprintf(buf, sizeof(buf), "%d", d);
return buf; return buf;
} }
NOXREF char *UTIL_dtos3(int d) NOXREF char *UTIL_dtos3(int d)
{ {
static char buf[12]; static char buf[12];
Q_sprintf(buf, "%d", d); Q_snprintf(buf, sizeof(buf), "%d", d);
return buf; return buf;
} }
NOXREF char *UTIL_dtos4(int d) NOXREF char *UTIL_dtos4(int d)
{ {
static char buf[12]; static char buf[12];
Q_sprintf(buf, "%d", d); Q_snprintf(buf, sizeof(buf), "%d", d);
return buf; return buf;
} }
@ -991,7 +979,7 @@ char *UTIL_VarArgs(char *format, ...)
static char string[1024]; static char string[1024];
va_start(argptr, format); va_start(argptr, format);
vsprintf(string, format, argptr); Q_vsnprintf(string, sizeof(string), format, argptr);
va_end(argptr); va_end(argptr);
return string; return string;
@ -1561,7 +1549,7 @@ void UTIL_LogPrintf(const char *fmt, ...)
static char string[1024]; static char string[1024];
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(string, fmt, argptr); Q_vsnprintf(string, sizeof(string), fmt, argptr);
va_end(argptr); va_end(argptr);
ALERT(at_logged, "%s", string); ALERT(at_logged, "%s", string);
@ -1580,7 +1568,7 @@ char UTIL_TextureHit(TraceResult *ptr, Vector vecSrc, Vector vecEnd)
float rgfl1[3]; float rgfl1[3];
float rgfl2[3]; float rgfl2[3];
const char *pTextureName; const char *pTextureName;
char szbuffer[64]; char szbuffer[MAX_TEXTURENAME_LENGHT];
CBaseEntity *pEntity = CBaseEntity::Instance(ptr->pHit); CBaseEntity *pEntity = CBaseEntity::Instance(ptr->pHit);
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
@ -1606,8 +1594,8 @@ char UTIL_TextureHit(TraceResult *ptr, Vector vecSrc, Vector vecEnd)
if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ') if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ')
pTextureName++; pTextureName++;
Q_strcpy(szbuffer, pTextureName); Q_strlcpy(szbuffer, pTextureName);
szbuffer[16] = '\0';
chTextureType = TEXTURETYPE_Find(szbuffer); chTextureType = TEXTURETYPE_Find(szbuffer);
} }
else else

View File

@ -652,11 +652,11 @@ void CBasePlayerWeapon::SetPlayerShieldAnim()
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shield"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shield");
} }
else else
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgun"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgun");
} }
} }
@ -666,7 +666,7 @@ void CBasePlayerWeapon::ResetPlayerShieldAnim()
{ {
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgun"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgun");
} }
} }
} }
@ -697,7 +697,7 @@ bool CBasePlayerWeapon::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
{ {
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN; m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iDownAnim, UseDecrement() != FALSE); SendWeaponAnim(iDownAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgun"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgun");
m_fMaxSpeed = 250.0f; m_fMaxSpeed = 250.0f;
m_pPlayer->m_bShieldDrawn = false; m_pPlayer->m_bShieldDrawn = false;
} }
@ -705,7 +705,7 @@ bool CBasePlayerWeapon::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
{ {
m_iWeaponState |= WPNSTATE_SHIELD_DRAWN; m_iWeaponState |= WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iUpAnim, UseDecrement() != FALSE); SendWeaponAnim(iUpAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shielded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shielded");
m_fMaxSpeed = 180.0f; m_fMaxSpeed = 180.0f;
m_pPlayer->m_bShieldDrawn = true; m_pPlayer->m_bShieldDrawn = true;
} }
@ -728,7 +728,7 @@ void EXT_FUNC CBasePlayerWeapon::__API_HOOK(KickBack)(float up_base, float later
real_t flKickUp = up_base; real_t flKickUp = up_base;
float flKickLateral = lateral_base; float flKickLateral = lateral_base;
if (m_iShotsFired > 1) // consider == 0 case if (m_iShotsFired > 1) // consider == 0 case
{ {
flKickUp += m_iShotsFired * up_modifier; flKickUp += m_iShotsFired * up_modifier;
flKickLateral += m_iShotsFired * lateral_modifier; flKickLateral += m_iShotsFired * lateral_modifier;
@ -1491,7 +1491,7 @@ BOOL EXT_FUNC CBasePlayerWeapon::__API_HOOK(DefaultDeploy)(char *szViewModel, ch
m_pPlayer->pev->weaponmodel = MAKE_STRING(szWeaponModel); m_pPlayer->pev->weaponmodel = MAKE_STRING(szWeaponModel);
#endif #endif
model_name = m_pPlayer->pev->viewmodel; model_name = m_pPlayer->pev->viewmodel;
Q_strcpy(m_pPlayer->m_szAnimExtention, szAnimExt); Q_strlcpy(m_pPlayer->m_szAnimExtention, szAnimExt);
SendWeaponAnim(iAnim, skiplocal); SendWeaponAnim(iAnim, skiplocal);
m_pPlayer->m_flNextAttack = 0.75f; m_pPlayer->m_flNextAttack = 0.75f;
@ -1671,7 +1671,7 @@ void CBasePlayerWeapon::Holster(int skiplocal)
m_fInReload = FALSE; m_fInReload = FALSE;
m_pPlayer->pev->viewmodel = 0; m_pPlayer->pev->viewmodel = 0;
m_pPlayer->pev->weaponmodel = 0; m_pPlayer->pev->weaponmodel = 0;
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
m_fInSpecialReload = 0; m_fInSpecialReload = 0;
#endif #endif

View File

@ -216,7 +216,7 @@ void CWorld::Spawn()
Precache(); Precache();
g_szMapBriefingText[0] = '\0'; g_szMapBriefingText[0] = '\0';
Q_sprintf(szMapBriefingFile, "maps/%s.txt", STRING(gpGlobals->mapname)); Q_snprintf(szMapBriefingFile, sizeof(szMapBriefingFile), "maps/%s.txt", STRING(gpGlobals->mapname));
int flength = 0; int flength = 0;
char *pFile = (char *)LOAD_FILE_FOR_ME(szMapBriefingFile, &flength); char *pFile = (char *)LOAD_FILE_FOR_ME(szMapBriefingFile, &flength);

View File

@ -114,7 +114,7 @@ bool CFlashbang::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN; m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iDownAnim, UseDecrement() != FALSE); SendWeaponAnim(iDownAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
m_fMaxSpeed = FLASHBANG_MAX_SPEED; m_fMaxSpeed = FLASHBANG_MAX_SPEED;
m_pPlayer->m_bShieldDrawn = false; m_pPlayer->m_bShieldDrawn = false;
@ -124,7 +124,7 @@ bool CFlashbang::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
m_iWeaponState |= WPNSTATE_SHIELD_DRAWN; m_iWeaponState |= WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iUpAnim, UseDecrement() != FALSE); SendWeaponAnim(iUpAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shielded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shielded");
m_fMaxSpeed = FLASHBANG_MAX_SPEED_SHIELD; m_fMaxSpeed = FLASHBANG_MAX_SPEED_SHIELD;
m_pPlayer->m_bShieldDrawn = true; m_pPlayer->m_bShieldDrawn = true;
@ -151,9 +151,9 @@ void CFlashbang::SetPlayerShieldAnim()
return; return;
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
Q_strcpy(m_pPlayer->m_szAnimExtention, "shield"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shield");
else else
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
} }
void CFlashbang::ResetPlayerShieldAnim() void CFlashbang::ResetPlayerShieldAnim()
@ -163,7 +163,7 @@ void CFlashbang::ResetPlayerShieldAnim()
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
} }
} }

View File

@ -117,7 +117,7 @@ bool CHEGrenade::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
{ {
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN; m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iDownAnim, UseDecrement() != FALSE); SendWeaponAnim(iDownAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
m_fMaxSpeed = HEGRENADE_MAX_SPEED; m_fMaxSpeed = HEGRENADE_MAX_SPEED;
m_pPlayer->m_bShieldDrawn = false; m_pPlayer->m_bShieldDrawn = false;
@ -126,7 +126,7 @@ bool CHEGrenade::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
{ {
m_iWeaponState |= WPNSTATE_SHIELD_DRAWN; m_iWeaponState |= WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iUpAnim, UseDecrement() != FALSE); SendWeaponAnim(iUpAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shielded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shielded");
m_fMaxSpeed = HEGRENADE_MAX_SPEED_SHIELD; m_fMaxSpeed = HEGRENADE_MAX_SPEED_SHIELD;
m_pPlayer->m_bShieldDrawn = true; m_pPlayer->m_bShieldDrawn = true;
@ -153,9 +153,9 @@ void CHEGrenade::SetPlayerShieldAnim()
return; return;
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
Q_strcpy(m_pPlayer->m_szAnimExtention, "shield"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shield");
else else
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
} }
void CHEGrenade::ResetPlayerShieldAnim() void CHEGrenade::ResetPlayerShieldAnim()
@ -165,7 +165,7 @@ void CHEGrenade::ResetPlayerShieldAnim()
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
} }
} }

View File

@ -180,7 +180,7 @@ void CKnife::SetPlayerShieldAnim()
if (!m_pPlayer->HasShield()) if (!m_pPlayer->HasShield())
return; return;
Q_strcpy(m_pPlayer->m_szAnimExtention, (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) != 0 ? "shield" : "shieldknife"); Q_strlcpy(m_pPlayer->m_szAnimExtention, (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) != 0 ? "shield" : "shieldknife");
} }
void CKnife::ResetPlayerShieldAnim() void CKnife::ResetPlayerShieldAnim()
@ -190,7 +190,7 @@ void CKnife::ResetPlayerShieldAnim()
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldknife"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldknife");
} }
} }
@ -207,7 +207,7 @@ bool CKnife::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
SendWeaponAnim(iDownAnim, UseDecrement() != FALSE); SendWeaponAnim(iDownAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldknife"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldknife");
m_fMaxSpeed = KNIFE_MAX_SPEED; m_fMaxSpeed = KNIFE_MAX_SPEED;
m_pPlayer->m_bShieldDrawn = false; m_pPlayer->m_bShieldDrawn = false;
@ -217,7 +217,7 @@ bool CKnife::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
m_iWeaponState |= WPNSTATE_SHIELD_DRAWN; m_iWeaponState |= WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iUpAnim, UseDecrement() != FALSE); SendWeaponAnim(iUpAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shielded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shielded");
m_fMaxSpeed = KNIFE_MAX_SPEED_SHIELD; m_fMaxSpeed = KNIFE_MAX_SPEED_SHIELD;
m_pPlayer->m_bShieldDrawn = true; m_pPlayer->m_bShieldDrawn = true;
@ -339,14 +339,14 @@ BOOL CKnife::Swing(BOOL fFirst)
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
// play wiff or swish sound // play wiff or swish sound
EMIT_SOUND_DYN(m_pPlayer->edict(), EMIT_SOUND_DYN(m_pPlayer->edict(),
CHAN_WEAPON, CHAN_WEAPON,
RANDOM_LONG(0, 1) ? RANDOM_LONG(0, 1) ?
"weapons/knife_slash1.wav" : "weapons/knife_slash1.wav" :
"weapons/knife_slash2.wav", "weapons/knife_slash2.wav",
VOL_NORM, VOL_NORM,
ATTN_NORM, ATTN_NORM,
0, 0,
94); 94);
// player "shoot" animation // player "shoot" animation
@ -390,10 +390,10 @@ BOOL CKnife::Swing(BOOL fFirst)
m_pPlayer->SetAnimation(PLAYER_ATTACK1); m_pPlayer->SetAnimation(PLAYER_ATTACK1);
ClearMultiDamage(); ClearMultiDamage();
pEntity->TraceAttack(m_pPlayer->pev, pEntity->TraceAttack(m_pPlayer->pev,
KnifeSwingDamage(m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()), KnifeSwingDamage(m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()),
gpGlobals->v_forward, gpGlobals->v_forward,
&tr, &tr,
(DMG_NEVERGIB | DMG_BULLET)); (DMG_NEVERGIB | DMG_BULLET));
ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev); ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);
@ -402,7 +402,7 @@ BOOL CKnife::Swing(BOOL fFirst)
if (pEntity) // -V595 if (pEntity) // -V595
#endif #endif
{ {
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
&& pEntity->Classify() != CLASS_VEHICLE && pEntity->Classify() != CLASS_VEHICLE
#endif #endif
@ -518,14 +518,14 @@ BOOL CKnife::Stab(BOOL fFirst)
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f; m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f;
// play wiff or swish sound // play wiff or swish sound
EMIT_SOUND_DYN(m_pPlayer->edict(), EMIT_SOUND_DYN(m_pPlayer->edict(),
CHAN_WEAPON, CHAN_WEAPON,
RANDOM_LONG(0, 1) ? RANDOM_LONG(0, 1) ?
"weapons/knife_slash1.wav" : "weapons/knife_slash1.wav" :
"weapons/knife_slash2.wav", "weapons/knife_slash2.wav",
VOL_NORM, VOL_NORM,
ATTN_NORM, ATTN_NORM,
0, 0,
94); 94);
// player "shoot" animation // player "shoot" animation
@ -586,7 +586,7 @@ BOOL CKnife::Stab(BOOL fFirst)
if (pEntity) // -V595 if (pEntity) // -V595
#endif #endif
{ {
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
&& pEntity->Classify() != CLASS_VEHICLE && pEntity->Classify() != CLASS_VEHICLE
#endif #endif

View File

@ -82,13 +82,13 @@ void CM4A1::SecondaryAttack()
{ {
m_iWeaponState &= ~WPNSTATE_M4A1_SILENCED; m_iWeaponState &= ~WPNSTATE_M4A1_SILENCED;
SendWeaponAnim(M4A1_DETACH_SILENCER, UseDecrement() != FALSE); SendWeaponAnim(M4A1_DETACH_SILENCER, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "rifle"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "rifle");
} }
else else
{ {
m_iWeaponState |= WPNSTATE_M4A1_SILENCED; m_iWeaponState |= WPNSTATE_M4A1_SILENCED;
SendWeaponAnim(M4A1_ATTACH_SILENCER, UseDecrement() != FALSE); SendWeaponAnim(M4A1_ATTACH_SILENCER, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "rifle"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "rifle");
} }
m_flTimeWeaponIdle = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 2.0f; m_flTimeWeaponIdle = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 2.0f;

View File

@ -117,7 +117,7 @@ bool CSmokeGrenade::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN; m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iDownAnim, UseDecrement() != FALSE); SendWeaponAnim(iDownAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
m_fMaxSpeed = SMOKEGRENADE_MAX_SPEED; m_fMaxSpeed = SMOKEGRENADE_MAX_SPEED;
m_pPlayer->m_bShieldDrawn = false; m_pPlayer->m_bShieldDrawn = false;
@ -127,7 +127,7 @@ bool CSmokeGrenade::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
m_iWeaponState |= WPNSTATE_SHIELD_DRAWN; m_iWeaponState |= WPNSTATE_SHIELD_DRAWN;
SendWeaponAnim(iUpAnim, UseDecrement() != FALSE); SendWeaponAnim(iUpAnim, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "shielded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shielded");
m_fMaxSpeed = SMOKEGRENADE_MAX_SPEED_SHIELD; m_fMaxSpeed = SMOKEGRENADE_MAX_SPEED_SHIELD;
m_pPlayer->m_bShieldDrawn = true; m_pPlayer->m_bShieldDrawn = true;
@ -154,9 +154,9 @@ void CSmokeGrenade::SetPlayerShieldAnim()
return; return;
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
Q_strcpy(m_pPlayer->m_szAnimExtention, "shield"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shield");
else else
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
} }
void CSmokeGrenade::ResetPlayerShieldAnim() void CSmokeGrenade::ResetPlayerShieldAnim()
@ -166,7 +166,7 @@ void CSmokeGrenade::ResetPlayerShieldAnim()
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{ {
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
} }
} }

View File

@ -98,14 +98,14 @@ void CUSP::SecondaryAttack()
m_iWeaponState &= ~WPNSTATE_USP_SILENCED; m_iWeaponState &= ~WPNSTATE_USP_SILENCED;
SendWeaponAnim(USP_DETACH_SILENCER, UseDecrement() != FALSE); SendWeaponAnim(USP_DETACH_SILENCER, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "onehanded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "onehanded");
} }
else else
{ {
m_iWeaponState |= WPNSTATE_USP_SILENCED; m_iWeaponState |= WPNSTATE_USP_SILENCED;
SendWeaponAnim(USP_ATTACH_SILENCER, UseDecrement() != FALSE); SendWeaponAnim(USP_ATTACH_SILENCER, UseDecrement() != FALSE);
Q_strcpy(m_pPlayer->m_szAnimExtention, "onehanded"); Q_strlcpy(m_pPlayer->m_szAnimExtention, "onehanded");
} }
m_flNextSecondaryAttack = m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + USP_ADJUST_SIL_TIME; m_flNextSecondaryAttack = m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + USP_ADJUST_SIL_TIME;

View File

@ -486,11 +486,11 @@ NOXREF void CBot::Print(char *format, ...) const
char buffer[1024]; char buffer[1024];
// prefix the message with the bot's name // prefix the message with the bot's name
Q_sprintf(buffer, "%s: ", STRING(pev->netname)); Q_snprintf(buffer, sizeof(buffer), "%s: ", STRING(pev->netname));
SERVER_PRINT(buffer); SERVER_PRINT(buffer);
va_start(varg, format); va_start(varg, format);
vsprintf(buffer, format, varg); Q_vsnprintf(buffer, sizeof(buffer), format, varg);
va_end(varg); va_end(varg);
SERVER_PRINT(buffer); SERVER_PRINT(buffer);
@ -509,12 +509,12 @@ void CBot::PrintIfWatched(char *format, ...) const
// prefix the message with the bot's name (this can be NULL if bot was just added) // prefix the message with the bot's name (this can be NULL if bot was just added)
const char *name = pev ? STRING(pev->netname) : "(NULL pev)"; const char *name = pev ? STRING(pev->netname) : "(NULL pev)";
Q_sprintf(buffer, "%s: ", name ? name : "(NULL netname)"); Q_snprintf(buffer, sizeof(buffer), "%s: ", name ? name : "(NULL netname)");
SERVER_PRINT(buffer); SERVER_PRINT(buffer);
va_start(varg, format); va_start(varg, format);
vsprintf(buffer, format, varg); Q_vsnprintf(buffer, sizeof(buffer), format, varg);
va_end(varg); va_end(varg);
SERVER_PRINT(buffer); SERVER_PRINT(buffer);

View File

@ -213,7 +213,7 @@ void CBotManager::StartFrame()
const char *CBotManager::GetNavMapFilename() const const char *CBotManager::GetNavMapFilename() const
{ {
static char filename[256]; static char filename[256];
Q_sprintf(filename, "maps\\%s.nav", STRING(gpGlobals->mapname)); Q_snprintf(filename, sizeof(filename), "maps\\%s.nav", STRING(gpGlobals->mapname));
return filename; return filename;
} }

View File

@ -178,9 +178,10 @@ void BotProfileManager::Init(const char *filename, unsigned int *checksum)
m_skins[m_nextSkin] = CloneString(decoratedName); m_skins[m_nextSkin] = CloneString(decoratedName);
// construct the model filename // construct the model filename
int SkinLen = Q_strlen(token) * 2 + Q_strlen("models/player//.mdl");
m_skinModelnames[m_nextSkin] = CloneString(token); m_skinModelnames[m_nextSkin] = CloneString(token);
m_skinFilenames[m_nextSkin] = new char[Q_strlen(token) * 2 + Q_strlen("models/player//.mdl") + 1]; m_skinFilenames[m_nextSkin] = new char[SkinLen + 1];
Q_sprintf(m_skinFilenames[m_nextSkin], "models/player/%s/%s.mdl", token, token); Q_snprintf(m_skinFilenames[m_nextSkin], SkinLen + 1, "models/player/%s/%s.mdl", token, token);
m_nextSkin++; m_nextSkin++;
} }
@ -304,7 +305,7 @@ void BotProfileManager::Init(const char *filename, unsigned int *checksum)
// found attribute name - keep it // found attribute name - keep it
char attributeName[64]; char attributeName[64];
Q_strcpy(attributeName, token); Q_strlcpy(attributeName, token);
// eat '=' // eat '='
dataFile = SharedParse(dataFile); dataFile = SharedParse(dataFile);

View File

@ -560,7 +560,7 @@ void CONSOLE_ECHO(const char *pszMsg, ...)
static char szStr[1024]; static char szStr[1024];
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(szStr, pszMsg, argptr); Q_vsnprintf(szStr, sizeof(szStr), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(szStr); SERVER_PRINT(szStr);
@ -572,7 +572,7 @@ void CONSOLE_ECHO_LOGGED(const char *pszMsg, ...)
static char szStr[1024]; static char szStr[1024];
va_start(argptr, pszMsg); va_start(argptr, pszMsg);
vsprintf(szStr, pszMsg, argptr); Q_vsnprintf(szStr, sizeof(szStr), pszMsg, argptr);
va_end(argptr); va_end(argptr);
SERVER_PRINT(szStr); SERVER_PRINT(szStr);

View File

@ -3819,9 +3819,9 @@ void EditNavAreas(NavEditCmdType cmd)
name = TheNavAreaGrid.IDToName(area->GetPlace()); name = TheNavAreaGrid.IDToName(area->GetPlace());
if (name) if (name)
Q_strcpy(locName, name); Q_strlcpy(locName, name);
else else
Q_strcpy(locName, "ERROR"); Q_strlcpy(locName, "ERROR");
} }
else else
{ {

View File

@ -632,12 +632,15 @@ bool SaveNavigationMap(const char *filename)
void LoadLocationFile(const char *filename) void LoadLocationFile(const char *filename)
{ {
char locFilename[256]; char locFilename[256];
Q_strcpy(locFilename, filename); Q_strlcpy(locFilename, filename);
char *dot = Q_strchr(locFilename, '.'); char *dot = Q_strrchr(locFilename, '.');
if (dot) if (dot)
{ {
Q_strcpy(dot, ".loc"); int dotlen = dot - locFilename;
size_t remaining_size = sizeof(locFilename) - dotlen;
if (remaining_size > 0)
Q_snprintf(dot, remaining_size, ".loc");
int locDataLength; int locDataLength;
char *locDataFile = (char *)LOAD_FILE_FOR_ME(const_cast<char *>(locFilename), &locDataLength); char *locDataFile = (char *)LOAD_FILE_FOR_ME(const_cast<char *>(locFilename), &locDataLength);
@ -771,7 +774,7 @@ NavErrorType LoadNavigationMap()
// nav filename is derived from map filename // nav filename is derived from map filename
char filename[256]; char filename[256];
Q_sprintf(filename, "maps\\%s.nav", STRING(gpGlobals->mapname)); Q_snprintf(filename, sizeof(filename), "maps\\%s.nav", STRING(gpGlobals->mapname));
// free previous navigation map data // free previous navigation map data
DestroyNavigationMap(); DestroyNavigationMap();

View File

@ -123,7 +123,7 @@ void PM_InitTextureTypes()
j = Q_min(j, MAX_TEXTURENAME_LENGHT - 1 + i); j = Q_min(j, MAX_TEXTURENAME_LENGHT - 1 + i);
buffer[j] = '\0'; buffer[j] = '\0';
Q_strcpy(&(pm_grgszTextureName[pm_gcTextures++][0]), &(buffer[i])); Q_strlcpy(pm_grgszTextureName[pm_gcTextures++], &(buffer[i]));
} }
// Must use engine to free since we are in a .dll // Must use engine to free since we are in a .dll
@ -364,8 +364,7 @@ void PM_CatagorizeTextureType()
if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ') if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ')
pTextureName++; pTextureName++;
Q_strcpy(pmove->sztexturename, pTextureName); Q_strlcpy(pmove->sztexturename, pTextureName, MAX_TEXTURENAME_LENGHT);
pmove->sztexturename[MAX_TEXTURENAME_LENGHT - 1] = '\0';
// get texture type // get texture type
pmove->chtexturetype = PM_FindTextureType(pmove->sztexturename); pmove->chtexturetype = PM_FindTextureType(pmove->sztexturename);

View File

@ -156,40 +156,48 @@ inline char *Q_strlcpy(char *dest, const char *src, size_t size) {
// a safe variant of strcpy that truncates the result to fit in the destination buffer // a safe variant of strcpy that truncates the result to fit in the destination buffer
template <size_t size> template <size_t size>
char *Q_strlcpy(char (&dest)[size], const char *src) { char *Q_strlcpy(char (&dest)[size], const char *src) {
return Q_strlcpy(dest, src, size); return Q_strlcpy(static_cast<char *>(dest), src, size);
} }
// safely concatenate two strings. // safely concatenate two strings.
// a variant of strcat that truncates the result to fit in the destination buffer // a variant of strcat that truncates the result to fit in the destination buffer
template <size_t size> inline size_t Q_strlcat(char *dest, const char *src, size_t maxDestSize)
size_t Q_strlcat(char (&dest)[size], const char *src)
{ {
size_t srclen; // Length of source string size_t srclen; // Length of source string
size_t dstlen; // Length of destination string size_t dstlen; // Length of destination string
// Figure out how much room is left // Figure out how much room is left
dstlen = Q_strlen(dest); dstlen = strlen(dest);
size_t length = size - dstlen + 1; size_t unRemainingSize = maxDestSize - dstlen - 1;
if (!length) { // Sanity check in case dest doesn't contain a null termination
// No room, return immediately if (dstlen > (maxDestSize - 1))
return dstlen; dstlen = maxDestSize - 1;
if (unRemainingSize <= 0 || unRemainingSize > maxDestSize)
{
dest[dstlen] = '\0';
return dstlen; // No room, return immediately
} }
// Figure out how much room is needed // Figure out how much room is needed
srclen = Q_strlen(src); srclen = strlen(src);
// Copy the appropriate amount // Copy the appropriate amount
if (srclen > length) { if (srclen > unRemainingSize)
srclen = length; srclen = unRemainingSize;
}
Q_memcpy(dest + dstlen, src, srclen); Q_memcpy(dest + dstlen, src, srclen);
dest[dstlen + srclen] = '\0'; dest[dstlen + srclen] = '\0';
return dstlen + srclen; return dstlen + srclen;
} }
template <size_t size>
inline size_t Q_strlcat(char (&dest)[size], const char *src)
{
return Q_strlcat(static_cast<char *>(dest), src, size);
}
// Force slashes of either type to be = separator character // Force slashes of either type to be = separator character
inline void Q_FixSlashes(char *pname, char separator = CORRECT_PATH_SEPARATOR) inline void Q_FixSlashes(char *pname, char separator = CORRECT_PATH_SEPARATOR)
{ {

View File

@ -32,10 +32,10 @@ TEST(SinCosPrecision, SseMathFun, 10000)
double sse_sin = _mm_cvtss_f32(s); double sse_sin = _mm_cvtss_f32(s);
double sse_cos = _mm_cvtss_f32(c); double sse_cos = _mm_cvtss_f32(c);
sprintf(localbuf, "sin precision failure for angle=%f", i); Q_snprintf(localbuf, sizeof(localbuf), "sin precision failure for angle=%f", i);
DOUBLES_EQUAL(localbuf, x87_sin, sse_sin, 0.000001); DOUBLES_EQUAL(localbuf, x87_sin, sse_sin, 0.000001);
sprintf(localbuf, "cos precision failure for angle=%f", i); Q_snprintf(localbuf, sizeof(localbuf), "cos precision failure for angle=%f", i);
DOUBLES_EQUAL(localbuf, x87_cos, sse_cos, 0.000001); DOUBLES_EQUAL(localbuf, x87_cos, sse_cos, 0.000001);
} }
} }