Skip to content

Commit cd6da64

Browse files
committed
Resolving code review feedback
1 parent e5cf5c7 commit cd6da64

File tree

9 files changed

+49
-31
lines changed

9 files changed

+49
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ RingPrototypeClass::RingPrototypeClass (void)
12061206
RingPrototypeClass::RingPrototypeClass(RingRenderObjClass *ring)
12071207
{
12081208
::memset (&Definition, 0, sizeof (Definition));
1209-
strlcpy (Definition.Name, ring->Get_Name(), ARRAY_SIZE(Definition.Name));
1209+
strlcpy(Definition.Name, ring->Get_Name(), ARRAY_SIZE(Definition.Name));
12101210

12111211
Definition.AnimDuration = ring->AnimDuration;
12121212
Definition.Attributes = ring->Get_Flags ();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ const char * SphereRenderObjClass::Get_Name(void) const
437437
void SphereRenderObjClass::Set_Name(const char * name)
438438
{
439439
WWASSERT(name != NULL);
440-
WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
441-
strlcpy(Name, name, ARRAY_SIZE(Name));
440+
const size_t nameLen = strlcpy(Name, name, ARRAY_SIZE(Name));
441+
(void)nameLen; WWASSERT(nameLen < ARRAY_SIZE(Name));
442442
}
443443

444444

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ static void Get_W3D_Name (const char *filename, char *w3d_name)
533533
// Copy all characters from start to end (excluding 'end')
534534
// into the w3d_name buffer. Then capitalize the string.
535535
int num_chars = end - start;
536-
WWASSERT(num_chars <= W3D_NAME_LEN);
537-
strlcpy(w3d_name, start, min(W3D_NAME_LEN, num_chars));
536+
const size_t nameLen = strlcpy(w3d_name, start, min(W3D_NAME_LEN, num_chars));
537+
(void)nameLen; WWASSERT(nameLen < min(W3D_NAME_LEN, num_chars));
538538
strupr(w3d_name);
539539
}
540540

Core/Libraries/Source/WWVegas/WWLib/thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
ThreadClass::ThreadClass(const char *thread_name, ExceptionHandlerType exception_handler) : handle(0), running(false), thread_priority(0)
3535
{
3636
if (thread_name) {
37-
assert(strlen(thread_name) < sizeof(ThreadName) - 1);
38-
strlcpy(ThreadName, thread_name, ARRAY_SIZE(ThreadName));
37+
size_t nameLen = strlcpy(ThreadName, thread_name, ARRAY_SIZE(ThreadName));
38+
(void)nameLen; assert(nameLen < ARRAY_SIZE(ThreadName));
3939
} else {
4040
strcpy(ThreadName, "No name");;
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void PerfGather::reset()
349349
{
350350
PerfGather::termPerfDump();
351351

352-
strlcpy(s_buf, fname, ARRAY_SIZE(s_buf));
352+
strlcpy(s_buf, fname, _MAX_PATH);
353353

354354
char tmp[256];
355355
strlcpy(tmp, s_buf, ARRAY_SIZE(tmp));

GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ void BuddyThreadClass::errorCallback( GPConnection *con, GPErrorArg *arg )
504504
static void getNickForMessage( GPConnection *con, GPGetInfoResponseArg *arg, void *param )
505505
{
506506
BuddyResponse *resp = (BuddyResponse *)param;
507-
strlcpy(resp->arg.message.nick, arg->nick, ARRAY_SIZE(resp->arg.message.nick));
507+
static_assert(ARRAY_SIZE(arg->nick) <= ARRAY_SIZE(resp->arg.message.nick), "Incorrect array size");
508+
strcpy(resp->arg.message.nick, arg->nick);
508509
}
509510

510511
void BuddyThreadClass::messageCallback( GPConnection *con, GPRecvBuddyMessageArg *arg )
@@ -557,9 +558,12 @@ void BuddyThreadClass::connectCallback( GPConnection *con, GPConnectResponseArg
557558
DEBUG_LOG(("User Error: Create Account instead of Login. Fixing them..."));
558559
BuddyRequest req;
559560
req.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGIN;
560-
strlcpy(req.arg.login.nick, m_nick.c_str(), ARRAY_SIZE(req.arg.login.nick));
561-
strlcpy(req.arg.login.email, m_email.c_str(), ARRAY_SIZE(req.arg.login.email));
562-
strlcpy(req.arg.login.password, m_pass.c_str(), ARRAY_SIZE(req.arg.login.password));
561+
static_assert(ARRAY_SIZE(req.arg.login.nick) > 0, "Array size too small");
562+
strcpy(req.arg.login.nick, m_nick.c_str());
563+
static_assert(ARRAY_SIZE(req.arg.login.email) > 0, "Array size too small");
564+
strcpy(req.arg.login.email, m_email.c_str());
565+
static_assert(ARRAY_SIZE(req.arg.login.password) > 0, "Array size too small");
566+
strcpy(req.arg.login.password, m_pass.c_str());
563567
req.arg.login.hasFirewall = true;
564568
TheGameSpyBuddyMessageQueue->addRequest( req );
565569
return;
@@ -618,9 +622,12 @@ static void getInfoResponseForRequest( GPConnection *con, GPGetInfoResponseArg *
618622
{
619623
BuddyResponse *resp = (BuddyResponse *)param;
620624
resp->profile = arg->profile;
621-
strlcpy(resp->arg.request.nick, arg->nick, ARRAY_SIZE(resp->arg.request.nick));
622-
strlcpy(resp->arg.request.email, arg->email, ARRAY_SIZE(resp->arg.request.email));
623-
strlcpy(resp->arg.request.countrycode, arg->countrycode, ARRAY_SIZE(resp->arg.request.countrycode));
625+
static_assert(ARRAY_SIZE(arg->nick) <= ARRAY_SIZE(resp->arg.request.nick), "Incorrect array size");
626+
strcpy(resp->arg.request.nick, arg->nick);
627+
static_assert(ARRAY_SIZE(arg->email) <= ARRAY_SIZE(resp->arg.request.email), "Incorrect array size");
628+
strcpy(resp->arg.request.email, arg->email);
629+
static_assert(ARRAY_SIZE(arg->countrycode) <= ARRAY_SIZE(resp->arg.request.countrycode), "Incorrect array size");
630+
strcpy(resp->arg.request.countrycode, arg->countrycode);
624631
}
625632

626633
void BuddyThreadClass::requestCallback( GPConnection *con, GPRecvBuddyRequestArg *arg )
@@ -644,9 +651,12 @@ static void getInfoResponseForStatus(GPConnection * connection, GPGetInfoRespons
644651
{
645652
BuddyResponse *resp = (BuddyResponse *)param;
646653
resp->profile = arg->profile;
647-
strlcpy(resp->arg.status.nick, arg->nick, ARRAY_SIZE(resp->arg.status.nick));
648-
strlcpy(resp->arg.status.email, arg->email, ARRAY_SIZE(resp->arg.status.email));
649-
strlcpy(resp->arg.status.countrycode, arg->countrycode, ARRAY_SIZE(resp->arg.status.countrycode));
654+
static_assert(ARRAY_SIZE(arg->nick) <= ARRAY_SIZE(resp->arg.status.nick), "Incorrect array size");
655+
strcpy(resp->arg.status.nick, arg->nick);
656+
static_assert(ARRAY_SIZE(arg->email) <= ARRAY_SIZE(resp->arg.status.email), "Incorrect array size");
657+
strcpy(resp->arg.status.email, arg->email);
658+
static_assert(ARRAY_SIZE(arg->countrycode) <= ARRAY_SIZE(resp->arg.status.countrycode), "Incorrect array size");
659+
strcpy(resp->arg.status.countrycode, arg->countrycode);
650660
}
651661

652662
void BuddyThreadClass::statusCallback( GPConnection *con, GPRecvBuddyStatusArg *arg )
@@ -660,8 +670,11 @@ void BuddyThreadClass::statusCallback( GPConnection *con, GPRecvBuddyStatusArg *
660670
// get user's status
661671
GPBuddyStatus status;
662672
gpGetBuddyStatus( con, arg->index, &status );
663-
strlcpy(response.arg.status.location, status.locationString, ARRAY_SIZE(response.arg.status.location));
664-
strlcpy(response.arg.status.statusString, status.statusString, ARRAY_SIZE(response.arg.status.statusString));
673+
674+
static_assert(ARRAY_SIZE(status.locationString) <= ARRAY_SIZE(response.arg.status.location), "Incorrect array size");
675+
strcpy(response.arg.status.location, status.locationString);
676+
static_assert(ARRAY_SIZE(status.statusString) <= ARRAY_SIZE(response.arg.status.statusString), "Incorrect array size");
677+
strcpy(response.arg.status.statusString, status.statusString);
665678
response.arg.status.status = status.status;
666679
DEBUG_LOG(("Got buddy status for %d(%s) - status %d", status.profile, response.arg.status.nick, status.status));
667680

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,9 +2751,9 @@ void W3DModelDraw::setTerrainDecal(TerrainDecalType type)
27512751
//decalInfo.m_type = SHADOW_ADDITIVE_DECAL;//temporary kluge to test graphics
27522752

27532753
if (type == TERRAIN_DECAL_SHADOW_TEXTURE)
2754-
strlcpy(decalInfo.m_ShadowName,tmplate->getShadowTextureName().str(), ARRAY_SIZE(decalInfo.m_ShadowName));
2754+
strlcpy(decalInfo.m_ShadowName, tmplate->getShadowTextureName().str(), ARRAY_SIZE(decalInfo.m_ShadowName));
27552755
else
2756-
strlcpy(decalInfo.m_ShadowName,TerrainDecalTextureName[type], ARRAY_SIZE(decalInfo.m_ShadowName));
2756+
strlcpy(decalInfo.m_ShadowName, TerrainDecalTextureName[type], ARRAY_SIZE(decalInfo.m_ShadowName));
27572757
decalInfo.m_sizeX = tmplate->getShadowSizeX();
27582758
decalInfo.m_sizeY = tmplate->getShadowSizeY();
27592759
decalInfo.m_offsetX = tmplate->getShadowOffsetX();

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S
17181718
//onto world geometry.
17191719
if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object
17201720
{
1721-
strlcpy(texture_name, defaultDecalName, ARRAY_SIZE(texture_name));
1721+
static_assert(ARRAY_SIZE(defaultDecalName) < ARRAY_SIZE(texture_name), "Incorrect array size");
1722+
strcpy(texture_name, defaultDecalName);
17221723
}
17231724
else
17241725
{
@@ -1894,7 +1895,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT
18941895
//onto world geometry.
18951896
if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object
18961897
{
1897-
strlcpy(texture_name, defaultDecalName, ARRAY_SIZE(texture_name));
1898+
static_assert(ARRAY_SIZE(defaultDecalName) < ARRAY_SIZE(texture_name), "Incorrect array size");
1899+
strcpy(texture_name, defaultDecalName);
18981900
}
18991901
else
19001902
{

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,16 @@ char const * GameFileClass::Set_Name( char const *filename )
197197
if( fileType == FILE_TYPE_W3D )
198198
{
199199

200-
strlcpy(m_filePath, W3D_DIR_PATH, ARRAY_SIZE(m_filePath));
200+
static_assert(ARRAY_SIZE(W3D_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size");
201+
strcpy(m_filePath, W3D_DIR_PATH);
201202
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
202203

203204
}
204205
else if( isImageFileType(fileType) )
205206
{
206207

207-
strlcpy(m_filePath, TGA_DIR_PATH, ARRAY_SIZE(m_filePath));
208+
static_assert(ARRAY_SIZE(TGA_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size");
209+
strcpy(m_filePath, TGA_DIR_PATH);
208210
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
209211

210212
}
@@ -225,13 +227,15 @@ char const * GameFileClass::Set_Name( char const *filename )
225227
if( fileType == FILE_TYPE_W3D )
226228
{
227229

230+
static_assert(ARRAY_SIZE(LEGACY_W3D_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size");
228231
strcpy(m_filePath, LEGACY_W3D_DIR_PATH, ARRAY_SIZE(m_filePath));
229232
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
230233

231234
}
232235
else if( isImageFileType(fileType) )
233236
{
234237

238+
static_assert(ARRAY_SIZE(LEGACY_TGA_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size");
235239
strcpy(m_filePath, LEGACY_TGA_DIR_PATH, ARRAY_SIZE(m_filePath));
236240
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
237241

@@ -253,14 +257,16 @@ char const * GameFileClass::Set_Name( char const *filename )
253257
if( fileType == FILE_TYPE_W3D )
254258
{
255259

256-
strlcpy(m_filePath, TEST_W3D_DIR_PATH, ARRAY_SIZE(m_filePath));
260+
static_assert(ARRAY_SIZE(TEST_W3D_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size");
261+
strcpy(m_filePath, TEST_W3D_DIR_PATH);
257262
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
258263

259264
}
260265
else if( isImageFileType(fileType) )
261266
{
262267

263-
strlcpy(m_filePath, TEST_TGA_DIR_PATH, ARRAY_SIZE(m_filePath));
268+
static_assert(ARRAY_SIZE(TEST_TGA_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size");
269+
strcpy(m_filePath, TEST_TGA_DIR_PATH);
264270
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
265271

266272
}
@@ -277,14 +283,12 @@ char const * GameFileClass::Set_Name( char const *filename )
277283
if( fileType == FILE_TYPE_W3D )
278284
{
279285
sprintf(m_filePath,USER_W3D_DIR_PATH, TheGlobalData->getPath_UserData().str());
280-
//strlcpy(m_filePath, USER_W3D_DIR_PATH, ARRAY_SIZE(m_filePath));
281286
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
282287

283288
}
284289
else if( isImageFileType(fileType) )
285290
{
286291
sprintf(m_filePath,USER_TGA_DIR_PATH, TheGlobalData->getPath_UserData().str());
287-
//strlcpy(m_filePath, USER_TGA_DIR_PATH, ARRAY_SIZE(m_filePath));
288292
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
289293

290294
}
@@ -301,7 +305,6 @@ char const * GameFileClass::Set_Name( char const *filename )
301305
if( fileType == FILE_TYPE_TGA ) // just TGA, since we don't do dds previews
302306
{
303307
sprintf(m_filePath,MAP_PREVIEW_DIR_PATH, TheGlobalData->getPath_UserData().str());
304-
//strlcpy(m_filePath, USER_TGA_DIR_PATH, ARRAY_SIZE(m_filePath));
305308
strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath));
306309

307310
}

0 commit comments

Comments
 (0)