Skip to content

Commit 38188de

Browse files
committed
Resolving code review feedback
1 parent 3dfe8bc commit 38188de

File tree

32 files changed

+104
-148
lines changed

32 files changed

+104
-148
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/registry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void RegistryClass::Save_Registry_Values(HKEY key, char *path, INIClass *ini)
403403
** Handle binary values.
404404
*/
405405
case REG_BINARY:
406-
strlcpy(save_name, "BIN_", ARRAY_SIZE(save_name));
406+
strcpy(save_name, "BIN_");
407407
strlcat(save_name, value_name, ARRAY_SIZE(save_name));
408408
ini->Put_UUBlock(path, save_name, (char*)data, data_size);
409409
break;

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/Common/System/SaveGame/GameState.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,15 @@ static AsciiString getMapLeafAndDirName(const AsciiString& in)
847847
// ------------------------------------------------------------------------------------------------
848848
static AsciiString removeExtension(const AsciiString& in)
849849
{
850-
char buf[1024];
851-
strlcpy(buf, in.str(), ARRAY_SIZE(buf));
852-
char* p = strrchr(buf, '.');
853-
if (p)
850+
if (const char* end = in.reverseFind('.'))
854851
{
855-
*p = 0;
852+
const char* begin = in.str();
853+
return AsciiString(begin, end - begin);
854+
}
855+
else
856+
{
857+
return in;
856858
}
857-
return AsciiString(buf);
858859
}
859860

860861
// ------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,9 @@ void JoinDirectConnectGame()
219219
AsciiString ipstring;
220220
asciientry.nextToken(&ipstring, "(");
221221

222-
char ipstr[16];
223-
strlcpy(ipstr, ipstring.str(), ARRAY_SIZE(ipstr));
224-
225222
Int ip1, ip2, ip3, ip4;
226-
sscanf(ipstr, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
223+
Int numFields = sscanf(ipstring.str(), "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
224+
DEBUG_ASSERTCRASH(numFields == 4, ("JoinDirectConnectGame - invalid IP address format: %s", ipstring.str()));
227225

228226
DEBUG_LOG(("JoinDirectConnectGame - joining at %d.%d.%d.%d", ip1, ip2, ip3, ip4));
229227

GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,11 +2627,10 @@ void ScriptActions::doDisplayCinematicText(const AsciiString& displayText, const
26272627

26282628
// get the font name
26292629
AsciiString fontName = AsciiString::TheEmptyString;
2630-
char buf[256];
2631-
char *c;
2632-
strlcpy(buf, fontType.str(), ARRAY_SIZE(buf));
2630+
26332631
// TheSuperHackers @fix xezon 16/03/2025 Fixes potential buffer overrun via prior c!='\0' test.
2634-
for( c = buf; *c != '\0'; c++ )
2632+
const char* c = fontType.str();
2633+
for (; *c != '\0'; c++)
26352634
{
26362635
if( *c != ' ' && *c++ != '-' )
26372636
fontName.concat(c);

GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,7 @@ Parameter *Parameter::ReadParameter(DataChunkInput &file)
21382138
char newName[256];
21392139
strlcpy(oldName, pParm->m_string.str(), ARRAY_SIZE(oldName));
21402140
strcpy(newName, "GLA");
2141+
static_assert(ARRAY_SIZE(oldName) >= ARRAY_SIZE("GLA"), "oldname buffer too small");
21412142
strlcat(newName, oldName+strlen("Fundamentalist"), ARRAY_SIZE(newName));
21422143
pParm->m_string.set(newName);
21432144
DEBUG_LOG(("Changing Script Ref from %s to %s", oldName, newName));

0 commit comments

Comments
 (0)