Skip to content

Commit

Permalink
Fixed minor bugs and replace 'strstr()' -> 'strchr()' for code optimi…
Browse files Browse the repository at this point in the history
…zation
  • Loading branch information
GermanAizek committed Sep 22, 2022
1 parent 4cb38cd commit a073c45
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rehlds/HLTV/Core/src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ bool Network::ResolveAddress(char *string, NetAddress *address)

// Parse address
// Validate IPv4
if (copy[0] >= '0' && copy[0] <= '9' && Q_strstr(copy, "."))
if (copy[0] >= '0' && copy[0] <= '9' && Q_strchr(copy, '.'))
{
uint32 ret = inet_addr(copy);
if (ret == INADDR_NONE) {
Expand Down
2 changes: 0 additions & 2 deletions rehlds/HLTV/Core/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,8 +1911,6 @@ void Server::ParseInfo(BitBuffer *stream, bool detailed)
si.ver = 0;
si.size = 0;
}

stream->ReadByte();
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions rehlds/HLTV/Director/src/Director.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ void Director::RunFrame(double time)

void Director::ReceiveSignal(ISystemModule *module, unsigned int signal, void *data)
{
int from = module->GetSerial();
if (m_World->GetSerial() != from) {
if (!m_World) {
m_System->Printf("Director::ReceiveSignal: world == NULL\n");
return;
}

if (signal != 3) {
int from = module->GetSerial();
if (m_World->GetSerial() != from) {
return;
}

if (!m_World) {
m_System->Printf("Director::ReceiveSignal: world == NULL\n");
if (signal != 3) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions rehlds/HLTV/common/DemoFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ bool DemoFile::StartRecording(char *newName)
COM_DefaultExtension(m_FileName, ".dem");

if (m_FileName[0] == '/'
|| Q_strstr(m_FileName, ":")
|| Q_strchr(m_FileName, ':')
|| Q_strstr(m_FileName, "..")
|| Q_strstr(m_FileName, "\\"))
|| Q_strchr(m_FileName, '\\'))
{
m_System->Printf("WARNING! DemoFile::StartRecording: unable to open %s (contains illegal characters).\n", m_FileName);
return false;
Expand Down
4 changes: 2 additions & 2 deletions rehlds/HLTV/common/InfoString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ void InfoString::RemovePrefixedKeys(char prefix)
bool InfoString::SetValueForStarKey(const char *key, const char *value)
{
char newtoken[MAX_INFO_LEN + 4];
if (Q_strstr(key, "\\") || Q_strstr(value, "\\")) {
if (Q_strchr(key, '\\') || Q_strchr(value, '\\')) {
return false;
}

if (Q_strstr(key, "\"") || Q_strstr(value, "\"")) {
if (Q_strchr(key, '\"') || Q_strchr(value, '\"')) {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion rehlds/HLTV/common/NetChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ void NetChannel::OutOfBandPrintf(const char *format, ...)
{
va_list argptr;
char string[NET_MAX_MESSAGE];
BitBuffer data(string, sizeof(string));

if (m_Socket)
{
BitBuffer data(string, sizeof(string));
*(int *)string = CONNECTIONLESS_HEADER;

va_start(argptr, format);
Expand Down Expand Up @@ -1173,6 +1173,7 @@ void NetChannel::CopyNormalFragments()

packet->data.Clear();
m_incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
delete packet;
return;
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions rehlds/common/commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ void CCommandLine::LoadParametersFromFile(const char *&pSrc, char *&pDst, int ma
FILE *fp = fopen(szFileName, "r");
if (fp)
{
char c;
c = (char)fgetc(fp);
while (c != EOF)
int c;
c = fgetc(fp);
while ((c = getchar()) != EOF)
{
// Turn return characters into spaces
if (c == '\n')
Expand All @@ -132,7 +132,7 @@ void CCommandLine::LoadParametersFromFile(const char *&pSrc, char *&pDst, int ma
#endif

// Get the next character, if there are more
c = (char)fgetc(fp);
c = fgetc(fp);
}

// Add a terminating space character
Expand Down
4 changes: 1 addition & 3 deletions rehlds/engine/ipratelimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ CIPRateLimit::CIPRateLimit() : m_IPTree(0, START_TREE_SIZE, LessIP)
m_lLastTime = -1;
}

CIPRateLimit::~CIPRateLimit()
{
}
CIPRateLimit::~CIPRateLimit() = default;

// Sort func for rb tree
bool CIPRateLimit::LessIP(const iprate_t &lhs, const iprate_t &rhs)
Expand Down
2 changes: 1 addition & 1 deletion rehlds/filesystem/FileSystem_Stdio/src/BaseFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ FileHandle_t CBaseFileSystem::Open(const char *pFileName, const char *pOptions,
{
// Try each of the search paths in succession
// FIXME: call createdirhierarchy upon opening for write.
if (Q_strstr(pOptions, "r") && !Q_strstr(pOptions, "+"))
if (Q_strchr(pOptions, 'r') && !Q_strchr(pOptions, '+'))
{
CUtlSymbol lookup(pathID);
for (int i = 0; i < m_SearchPaths.Count(); i++)
Expand Down

0 comments on commit a073c45

Please sign in to comment.