Skip to content

Commit 1d8c1d7

Browse files
author
G_Moris
committed
Fixed by Tederis
1 parent 5cd6fc3 commit 1d8c1d7

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

Client/core/CCommands.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ bool CCommands::Execute(const char* szCommandLine)
8484
bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind)
8585
{
8686
// Copy szParametersIn so the contents can be changed
87-
char* szParameters = nullptr;
87+
std::unique_ptr<char[]> szParameters = nullptr;
8888
if (szParametersIn)
8989
{
90-
szParameters = new char[strlen(szParametersIn) + 1];
91-
std::strcpy(szParameters, szParametersIn);
90+
szParameters = std::make_unique<char[]>(strlen(szParametersIn) + 1);
91+
std::strcpy(szParameters.get(), szParametersIn);
9292
}
9393

9494
// HACK: if its a 'chatboxsay' command, use the next parameter
@@ -98,21 +98,29 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
9898
if (szParameters)
9999
{
100100
// His line starts with '/'?
101-
if (*szParameters == '/')
101+
if (szParameters[0] == '/')
102102
{
103103
// Copy the characters after the slash to the 0 terminator to a seperate buffer
104104
char szBuffer[256];
105-
strncpy(szBuffer, szParameters + 1, 256);
105+
strncpy(szBuffer, szParameters.get() + 1, 256);
106106
szBuffer[255] = 0;
107107

108108
// Split it into command and arguments
109109
szCommand = strtok(szBuffer, " ");
110-
szParameters = strtok(nullptr, "\0");
111110
if (!szCommand)
112111
return false;
113112

114-
if (!szParameters)
115-
std::strcpy(szParameters, "");
113+
if (char* szNewParameters = strtok(nullptr, "\0"); szNewParameters)
114+
{
115+
szParameters = std::make_unique<char[]>(strlen(szNewParameters) + 1);
116+
std::strcpy(szParameters.get(), szNewParameters);
117+
}
118+
else
119+
{
120+
// Åñëè íåò ïàðàìåòðîâ, ñîçäàåì ïóñòóþ ñòðîêó
121+
szParameters = std::make_unique<char[]>(1);
122+
szParameters[0] = '\0';
123+
}
116124
}
117125
}
118126
else
@@ -128,12 +136,12 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
128136
{
129137
// Execute it
130138
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
131-
ExecuteHandler(pEntry->pfnCmdFunc, szParameters);
139+
ExecuteHandler(pEntry->pfnCmdFunc, szParameters.get());
132140
}
133141
}
134142

135143
// Recompose the original command text
136-
std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters : "");
144+
std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters.get() : "");
137145

138146
// Is it a cvar? (syntax: cvar[ = value])
139147
{
@@ -177,10 +185,6 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
177185
ss << key << " = " << val;
178186
val = ss.str();
179187
CCore::GetSingleton().GetConsole()->Print(val.c_str());
180-
181-
if (szParameters)
182-
delete[] szParameters;
183-
184188
return true;
185189
}
186190
}
@@ -189,13 +193,13 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
189193
bool bIsNickCommand = !stricmp(szCommand, "nick");
190194
if (bIsNickCommand && szParameters && !bIsScriptedBind)
191195
{
192-
if (CCore::GetSingleton().IsValidNick(szParameters))
196+
if (CCore::GetSingleton().IsValidNick(szParameters.get()))
193197
{
194-
CVARS_SET("nick", std::string(szParameters));
198+
CVARS_SET("nick", std::string(szParameters.get()));
195199

196200
if (!CCore::GetSingleton().IsConnected())
197201
{
198-
CCore::GetSingleton().GetConsole()->Printf("nick: You are now known as %s", szParameters);
202+
CCore::GetSingleton().GetConsole()->Printf("nick: You are now known as %s", szParameters.get());
199203
}
200204
}
201205
else if (!CCore::GetSingleton().IsConnected())
@@ -208,13 +212,8 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
208212
if (m_pfnExecuteHandler)
209213
{
210214
bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind);
211-
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind))
212-
{
213-
if (szParameters)
214-
delete[] szParameters;
215-
215+
if (m_pfnExecuteHandler(szCommand, szParameters.get(), bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind))
216216
return true;
217-
}
218217
}
219218

220219
// Unknown command

Client/core/CVersionUpdater.Util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ namespace
391391
SString GetAttribute(const SString& strName) const
392392
{
393393
const SString* pValue = MapFind(attributeMap, strName);
394-
return pValue ? *pValue : SStringX("");
394+
return pValue ? *pValue : SString();
395395
}
396396
void SetAttribute(const SString& strName, const SString& strValue) { MapSet(attributeMap, strName, strValue); }
397397
};

Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void CClientPerfStatLuaTimingImpl::OutputTimingBlock(CClientPerfStatResult* pRes
432432

433433
row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p) : SStringX("-");
434434
row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : SStringX("-");
435-
row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : SStringX("");
435+
row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : SString();
436436
row[c++] = avg_s > 0.0005 ? SString("%2.3f", avg_s).c_str() : bSubBlock ? "-" : "";
437437
row[c++] = max_s > 0.0005 ? SString("%2.3f", max_s).c_str() : bSubBlock ? "-" : "";
438438
}

Shared/sdk/SharedUtil.Logging.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ void SharedUtil::CycleFile(const SString& strPathFilename, uint uiCycleThreshKB,
167167
// Rename older files .1 .2 etc
168168
uint uiNew = uiNumBackups - 1 - i;
169169
uint uiOld = uiNumBackups - i;
170-
SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SStringX(""));
171-
SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SStringX(""));
170+
171+
SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SString());
172+
SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SString());
172173

173174
FileDelete(strFilenameOlder);
174175
FileRename(strFilenameNewer, strFilenameOlder);

0 commit comments

Comments
 (0)