Skip to content

Commit 162e6cb

Browse files
committed
Adjustements based on feedback
1 parent 702df7b commit 162e6cb

File tree

16 files changed

+63
-41
lines changed

16 files changed

+63
-41
lines changed

Core/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ void DebugInit(int flags)
381381
*(pEnd + 1) = 0;
382382
}
383383

384-
strlcpy(theLogFileNamePrev, dirbuf, ARRAY_SIZE(theLogFileNamePrev));
384+
static_assert(ARRAY_SIZE(theLogFileNamePrev) >= ARRAY_SIZE(dirbuf), "Incorrect array size");
385+
strcpy(theLogFileNamePrev, dirbuf);
385386
strlcat(theLogFileNamePrev, gAppPrefix, ARRAY_SIZE(theLogFileNamePrev));
386387
strlcat(theLogFileNamePrev, DEBUG_FILE_NAME_PREV, ARRAY_SIZE(theLogFileNamePrev));
387388
if (rts::ClientInstance::getInstanceId() > 1u)
@@ -391,7 +392,7 @@ void DebugInit(int flags)
391392
}
392393
strlcat(theLogFileNamePrev, ".txt", ARRAY_SIZE(theLogFileNamePrev));
393394

394-
strlcpy(theLogFileName, dirbuf, ARRAY_SIZE(theLogFileNamePrev));
395+
strcpy(theLogFileName, dirbuf);
395396
strlcat(theLogFileName, gAppPrefix, ARRAY_SIZE(theLogFileNamePrev));
396397
strlcat(theLogFileName, DEBUG_FILE_NAME, ARRAY_SIZE(theLogFileNamePrev));
397398
if (rts::ClientInstance::getInstanceId() > 1u)

Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ Bool StdLocalFileSystem::doesFileExist(const Char *filename) const
211211
void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirectory, const AsciiString& originalDirectory, const AsciiString& searchName, FilenameList & filenameList, Bool searchSubdirectories) const
212212
{
213213

214-
char search[_MAX_PATH];
215214
AsciiString asciisearch;
216215
asciisearch = originalDirectory;
217216
asciisearch.concat(currentDirectory);
@@ -227,17 +226,15 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect
227226
std::replace(fixedDirectory.begin(), fixedDirectory.end(), '\\', '/');
228227
#endif
229228

230-
strlcpy(search, fixedDirectory.c_str(), ARRAY_SIZE(search));
231-
232229
Bool done = FALSE;
233230
std::error_code ec;
234231

235-
auto iter = std::filesystem::directory_iterator(search, ec);
232+
auto iter = std::filesystem::directory_iterator(fixedDirectory.c_str(), ec);
236233
// The default iterator constructor creates an end iterator
237234
done = iter == std::filesystem::directory_iterator();
238235

239236
if (ec) {
240-
DEBUG_LOG(("StdLocalFileSystem::getFileListInDirectory - Error opening directory %s", search));
237+
DEBUG_LOG(("StdLocalFileSystem::getFileListInDirectory - Error opening directory %s", fixedDirectory.c_str()));
241238
return;
242239
}
243240

Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,14 @@ void Win32LocalFileSystem::getFileListInDirectory(const AsciiString& currentDire
127127
HANDLE fileHandle = NULL;
128128
WIN32_FIND_DATA findData;
129129

130-
char search[_MAX_PATH];
131130
AsciiString asciisearch;
132131
asciisearch = originalDirectory;
133132
asciisearch.concat(currentDirectory);
134133
asciisearch.concat(searchName);
135-
strlcpy(search, asciisearch.str(), ARRAY_SIZE(search));
136134

137135
Bool done = FALSE;
138136

139-
fileHandle = FindFirstFile(search, &findData);
137+
fileHandle = FindFirstFile(asciisearch.str(), &findData);
140138
done = (fileHandle == INVALID_HANDLE_VALUE);
141139

142140
while (!done) {

Core/Libraries/Source/WWVegas/WW3D2/collect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ WW3DErrorType CollectionDefClass::Load(ChunkLoadClass & cload)
10151015
if (cload.Read(&header,sizeof(header)) != sizeof(header)) goto Error;
10161016
if (!cload.Close_Chunk()) goto Error;
10171017

1018-
strlcpy(Name,header.Name,W3D_NAME_LEN);
1018+
static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(header.Name), "Incorrect array size");
1019+
strcpy(Name,header.Name);
10191020
ObjectNames.Resize(header.RenderObjectCount);
10201021

10211022
while (cload.Open_Chunk()) {

Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,16 @@ int HCompressedAnimClass::Load_W3D(ChunkLoadClass & cload)
255255

256256
cload.Close_Chunk();
257257

258-
strlcpy(Name, aheader.HierarchyName, ARRAY_SIZE(Name));
258+
static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size");
259+
strcpy(Name, aheader.HierarchyName);
259260
strlcat(Name, ".", ARRAY_SIZE(Name));
260261
strlcat(Name, aheader.Name, ARRAY_SIZE(Name));
261262

262263
// TSS chasing crash bug 05/26/99
263264
WWASSERT(HierarchyName != NULL);
264265
WWASSERT(aheader.HierarchyName != NULL);
265266
WWASSERT(sizeof(HierarchyName) >= W3D_NAME_LEN);
266-
strlcpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN);
267+
strcpy(HierarchyName,aheader.HierarchyName);
267268

268269
HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName);
269270
if (base_pose == NULL) {

Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ int HModelDefClass::Load_W3D(ChunkLoadClass & cload)
148148
/*
149149
** process the header info
150150
*/
151-
strlcpy(ModelName,header.Name,W3D_NAME_LEN);
152-
strlcpy(BasePoseName,header.HierarchyName,W3D_NAME_LEN);
153-
strlcpy(Name, ModelName, ARRAY_SIZE(Name));
151+
static_assert(ARRAY_SIZE(ModelName) >= ARRAY_SIZE(header.Name), "Incorrect array size");
152+
static_assert(ARRAY_SIZE(BasePoseName) >= ARRAY_SIZE(header.HierarchyName), "Incorrect array size");
153+
static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(ModelName), "Incorrect array size");
154+
strcpy(ModelName,header.Name);
155+
strcpy(BasePoseName,header.HierarchyName);
156+
strcpy(Name, ModelName);
154157

155158
/*
156159
** Just allocate a node for the number of sub objects we're expecting
@@ -232,7 +235,8 @@ bool HModelDefClass::read_connection(ChunkLoadClass & cload,HmdlNodeDefStruct *
232235
return false;
233236
}
234237

235-
strlcpy(node->RenderObjName, ModelName, ARRAY_SIZE(node->RenderObjName));
238+
static_assert(ARRAY_SIZE(node->RenderObjName) >= ARRAY_SIZE(ModelName), "Incorrect array size");
239+
strcpy(node->RenderObjName, ModelName);
236240
strlcat(node->RenderObjName, ".", ARRAY_SIZE(node->RenderObjName));
237241
strlcat(node->RenderObjName, con.RenderObjName, ARRAY_SIZE(node->RenderObjName));
238242

Generals/Code/GameEngine/Source/Common/PerfTimer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ void PerfGather::reset()
269269
{
270270
PerfGather::termPerfDump();
271271

272-
strlcpy(s_buf, fname, _MAX_PATH);
272+
strlcpy(s_buf, fname, ARRAY_SIZE(s_buf);
273273

274274
char tmp[256];
275-
strlcpy(tmp, s_buf, _MAX_PATH);
275+
strlcpy(tmp, s_buf, ARRAY_SIZE(tmp));
276276
strlcat(tmp, ".csv", ARRAY_SIZE(tmp));
277277

278278
s_perfStatsFile = fopen(tmp, "w");

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S
17631763
//to allow multiple models to share same shadow - for
17641764
//example, all trees could use same shadow even if slightly
17651765
//different color, etc.
1766-
strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name));
1766+
static_assert(ARRAY_SIZE(texture_name) >= ARRAY_SIZE(shadowInfo->m_ShadowName), "Incorrect array size");
1767+
strcpy(texture_name, shadowInfo->m_ShadowName);
17671768
}
17681769
else
17691770
strlcpy(texture_name, robj->Get_Name(), ARRAY_SIZE(texture_name)); //not texture name give, assume model name.

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,14 @@ Bool W3DBridge::load(BodyDamageType curDamageState)
234234
char section[_MAX_PATH];
235235
char right[_MAX_PATH];
236236

237-
strlcpy(left, modelName, ARRAY_SIZE(left));
237+
static_assert(ARRAY_SIZE(left) >= ARRAY_SIZE(section), "Incorrect array size");
238+
static_assert(ARRAY_SIZE(section) >= ARRAY_SIZE(modelName), "Incorrect array size");
239+
static_assert(ARRAY_SIZE(right) >= ARRAY_SIZE(modelName), "Incorrect array size");
240+
strcpy(left, modelName);
238241
strlcat(left, ".BRIDGE_LEFT", ARRAY_SIZE(left));
239-
strlcpy(section, modelName, ARRAY_SIZE(section));
242+
strcpy(section, modelName);
240243
strlcat(section, ".BRIDGE_SPAN", ARRAY_SIZE(section));
241-
strlcpy(right, modelName, ARRAY_SIZE(right));
244+
strcpy(right, modelName);
242245
strlcat(right, ".BRIDGE_RIGHT", ARRAY_SIZE(right));
243246

244247
m_bridgeTexture = pMgr->Get_Texture(textureFile, MIP_LEVELS_3);

Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,12 @@ int HMorphAnimClass::Load_W3D(ChunkLoadClass & cload)
549549
cload.Read(&header,sizeof(header));
550550
cload.Close_Chunk();
551551

552-
strlcpy(AnimName, header.Name, ARRAY_SIZE(AnimName));
553-
strlcpy(HierarchyName, header.HierarchyName, ARRAY_SIZE(HierarchyName));
554-
strlcpy(Name, HierarchyName, ARRAY_SIZE(Name));
552+
static_assert(ARRAY_SIZE(AnimName) >= ARRAY_SIZE(header.Name), "Incorrect array size");
553+
static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(header.HierarchyName), "Incorrect array size");
554+
static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(HierarchyName), "Incorrect array size");
555+
strcpy(AnimName, header.Name);
556+
strcpy(HierarchyName, header.HierarchyName);
557+
strcpy(Name, HierarchyName);
555558
strlcat(Name, ".", ARRAY_SIZE(Name));
556559
strlcat(Name, AnimName, ARRAY_SIZE(Name));
557560

0 commit comments

Comments
 (0)