Skip to content

Commit

Permalink
Client: Replace safe_strcpy with V_strcpy_safe
Browse files Browse the repository at this point in the history
  • Loading branch information
tmp64 committed Aug 24, 2024
1 parent 817cd22 commit b24daff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
14 changes: 1 addition & 13 deletions src/game/client/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cstring>
#include <algorithm>
#include <tier0/dbg.h>
#include <tier1/strtools.h>
#include "cvardef.h"
#include <convar.h>
#include "console.h"
Expand Down Expand Up @@ -125,19 +126,6 @@ inline void CenterPrint(const char *string)
gEngfuncs.pfnCenterPrint(string);
}

inline char *safe_strcpy(char *dst, const char *src, int len_dst)
{
if (len_dst <= 0)
{
return NULL; // this is bad
}

strncpy(dst, src, len_dst);
dst[len_dst - 1] = '\0';

return dst;
}

// sound functions
inline void PlaySound(const char *szSound, float vol) { gEngfuncs.pfnPlaySoundByName(szSound, vol); }
inline void PlaySound(int iSound, float vol) { gEngfuncs.pfnPlaySoundByIndex(iSound, vol); }
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/hud/statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void CHudStatusBar::ParseStatusString(int line_num)
GetPlayerInfo(indexval)->Update();
if (GetPlayerInfo(indexval)->IsConnected())
{
safe_strcpy(szRepString, GetPlayerInfo(indexval)->GetDisplayName(false), MAX_PLAYERNAME_LENGTH);
V_strcpy_safe(szRepString, GetPlayerInfo(indexval)->GetDisplayName(false));
gHUD.GetClientColorAsFloat(indexval, m_pflNameColors[line_num], NoTeamColor::Orange);
}
else
Expand Down
15 changes: 10 additions & 5 deletions src/game/client/hud/text_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,28 @@ int CHudTextMessage::MsgFunc_TextMsg(const char *pszName, int iSize, void *pbuf)

static char szBuf[6][MSG_BUF_SIZE];
char *msg_text = LookupString(READ_STRING(), &msg_dest);
msg_text = safe_strcpy(szBuf[0], msg_text, MSG_BUF_SIZE);
V_strcpy_safe(szBuf[0], msg_text);
msg_text = szBuf[0];

// keep reading strings and using C format strings for subsituting the strings into the localised text string
char *sstr1 = LookupString(READ_STRING());
sstr1 = safe_strcpy(szBuf[1], sstr1, MSG_BUF_SIZE);
V_strcpy_safe(szBuf[1], sstr1);
sstr1 = szBuf[1];
StripEndNewlineFromString(sstr1); // these strings are meant for subsitution into the main strings, so cull the automatic end newlines

char *sstr2 = LookupString(READ_STRING());
sstr2 = safe_strcpy(szBuf[2], sstr2, MSG_BUF_SIZE);
V_strcpy_safe(szBuf[2], sstr2);
sstr2 = szBuf[2];
StripEndNewlineFromString(sstr2);

char *sstr3 = LookupString(READ_STRING());
sstr3 = safe_strcpy(szBuf[3], sstr3, MSG_BUF_SIZE);
V_strcpy_safe(szBuf[3], sstr3);
sstr3 = szBuf[3];
StripEndNewlineFromString(sstr3);

char *sstr4 = LookupString(READ_STRING());
sstr4 = safe_strcpy(szBuf[4], sstr4, MSG_BUF_SIZE);
V_strcpy_safe(szBuf[4], sstr4);
sstr4 = szBuf[4];
StripEndNewlineFromString(sstr4);

char *psz = szBuf[5];
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ int V_FindViewModelByWeaponModel(int weaponindex)
// Model name not found in the modelmap array (possible for WeaponMod weapons).
// Construct view model name based on player model name.
char buf[128];
safe_strcpy(buf, weaponModel->name, sizeof(buf));
V_strcpy_safe(buf, weaponModel->name);
if (!strncmp(buf, "models/p_", 9))
{
// Replace "models/p_" with "models/v_"
Expand Down

0 comments on commit b24daff

Please sign in to comment.