Skip to content

Commit 84f15c6

Browse files
author
Bart Roossien
committed
Ditching const for ARRAY_SIZE
1 parent c7d5ebd commit 84f15c6

File tree

6 files changed

+35
-44
lines changed

6 files changed

+35
-44
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,10 +2974,9 @@ void MemoryPoolFactory::memoryPoolUsageReport( const char* filename, FILE *appen
29742974

29752975
if( !appendToFileInstead )
29762976
{
2977-
const int tmpSize = 256;
2978-
char tmp[tmpSize];
2977+
char tmp[256];
29792978
strcpy(tmp,filename);
2980-
strlcat(tmp,".csv", tmpSize);
2979+
strlcat(tmp,".csv", ARRAY_SIZE(tmp));
29812980
perfStatsFile = fopen(tmp, "w");
29822981
}
29832982
else
@@ -3202,13 +3201,12 @@ void MemoryPoolFactory::debugMemoryReport(Int flags, Int startCheckpoint, Int en
32023201
DEBUG_LOG(("------------------------------------------"));
32033202
DEBUG_LOG(("Begin Block Report for %s", nm));
32043203
DEBUG_LOG(("------------------------------------------"));
3205-
const int bufSize = 256;
3206-
char buf[bufSize] = "";
3207-
if (flags & _REPORT_CP_ALLOCATED_BEFORE) strlcat(buf, "AllocBefore ", bufSize);
3208-
if (flags & _REPORT_CP_ALLOCATED_BETWEEN) strlcat(buf, "AllocBetween ", bufSize);
3209-
if (flags & _REPORT_CP_FREED_BEFORE) strlcat(buf, "FreedBefore ", bufSize);
3210-
if (flags & _REPORT_CP_FREED_BETWEEN) strlcat(buf, "FreedBetween ", bufSize);
3211-
if (flags & _REPORT_CP_FREED_NEVER) strlcat(buf, "StillExisting ", bufSize);
3204+
char buf[256] = "";
3205+
if (flags & _REPORT_CP_ALLOCATED_BEFORE) strlcat(buf, "AllocBefore ", ARRAY_SIZE(buf));
3206+
if (flags & _REPORT_CP_ALLOCATED_BETWEEN) strlcat(buf, "AllocBetween ", ARRAY_SIZE(buf));
3207+
if (flags & _REPORT_CP_FREED_BEFORE) strlcat(buf, "FreedBefore ", ARRAY_SIZE(buf));
3208+
if (flags & _REPORT_CP_FREED_BETWEEN) strlcat(buf, "FreedBetween ", ARRAY_SIZE(buf));
3209+
if (flags & _REPORT_CP_FREED_NEVER) strlcat(buf, "StillExisting ", ARRAY_SIZE(buf));
32123210
DEBUG_LOG(("Options: Between checkpoints %d and %d, report on (%s)",startCheckpoint,endCheckpoint,buf));
32133211
DEBUG_LOG(("------------------------------------------"));
32143212

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ static const char * Make_W3D_Filename (const char *w3d_name)
558558

559559
// Copy the w3d name into a static buffer, turn it into lowercase
560560
// letters, and append a ".w3d" file extension. That's the filename.
561-
static const int bufferSize = 64;
562-
static char buffer[bufferSize];
561+
static char buffer[64];
563562
if (*w3d_name == 0)
564563
{
565564
// Empty W3D name case.
@@ -571,6 +570,6 @@ static const char * Make_W3D_Filename (const char *w3d_name)
571570
if (dot)
572571
*dot = 0;
573572
strlwr(buffer);
574-
strlcat(buffer, ".w3d", bufferSize);
573+
strlcat(buffer, ".w3d", ARRAY_SIZE(buffer));
575574
return buffer;
576575
}

Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,8 +1709,7 @@ HRESULT Cftp::FileRecoveryPosition( LPCSTR szLocalFileName, LPCSTR szRegistryRo
17091709
FILE * testfp;
17101710
HKEY hkey;
17111711
unsigned char regfilename[ 256 ];
1712-
const int regkeySize = 512;
1713-
char regkey[ regkeySize ];
1712+
char regkey[ 512 ];
17141713
unsigned long t1, t2;
17151714
17161715
if( ( szRegistryRoot == NULL ) || ( szLocalFileName == NULL ) )
@@ -1724,11 +1723,11 @@ HRESULT Cftp::FileRecoveryPosition( LPCSTR szLocalFileName, LPCSTR szRegistryRo
17241723
strcpy( regkey, szRegistryRoot );
17251724
if( regkey[ strlen( regkey ) - 1 ] != '\\' )
17261725
{
1727-
strlcat( regkey, "\\Download", regkeySize);
1726+
strlcat(regkey, "\\Download", ARRAY_SIZE(regkey));
17281727
}
17291728
else
17301729
{
1731-
strlcat( regkey, "Download", regkeySize);
1730+
strlcat(regkey, "Download", ARRAY_SIZE(regkey));
17321731
}
17331732
17341733
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, (LPCTSTR)regkey,

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
340340
/*
341341
** Scrap buffer for constructing dump strings
342342
*/
343-
const int scrapSize = 256;
344-
char scrap [scrapSize];
343+
char scrap [256];
345344

346345
/*
347346
** Clear out the dump buffer
@@ -654,15 +653,15 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
654653

655654
for (int c = 0 ; c < 32 ; c++) {
656655
if (IsBadReadPtr(eip_ptr, 1)) {
657-
strlcat(scrap, "?? ", scrapSize);
656+
strlcat(scrap, "?? ", ARRAY_SIZE(scrap));
658657
} else {
659658
sprintf(bytestr, "%02X ", *eip_ptr);
660-
strlcat(scrap, bytestr, scrapSize);
659+
strlcat(scrap, bytestr, ARRAY_SIZE(scrap));
661660
}
662661
eip_ptr++;
663662
}
664663

665-
strlcat(scrap, "\r\n\r\n", scrapSize);
664+
strlcat(scrap, "\r\n\r\n", ARRAY_SIZE(scrap));
666665
Add_Txt(scrap);
667666

668667
/*
@@ -678,14 +677,14 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
678677
** The stack contents cannot be read so just print up question marks.
679678
*/
680679
sprintf(scrap, "%p: ", static_cast<void*>(stackptr));
681-
strlcat(scrap, "????????\r\n", scrapSize);
680+
strlcat(scrap, "????????\r\n", ARRAY_SIZE(scrap));
682681
} else {
683682
/*
684683
** If this stack address is in our memory space then try to match it with a code symbol.
685684
*/
686685
if (IsBadCodePtr((FARPROC)*stackptr)) {
687686
sprintf(scrap, "%p: %08lX ", static_cast<void*>(stackptr), *stackptr);
688-
strlcat(scrap, "DATA_PTR\r\n", scrapSize);
687+
strlcat(scrap, "DATA_PTR\r\n", ARRAY_SIZE(scrap));
689688
} else {
690689
sprintf(scrap, "%p: %08lX", static_cast<void*>(stackptr), *stackptr);
691690

@@ -698,12 +697,12 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
698697
if (_SymGetSymFromAddr != NULL && _SymGetSymFromAddr (GetCurrentProcess(), *stackptr, &displacement, symptr)) {
699698
char symbuf[256];
700699
sprintf(symbuf, " - %s + %08X", symptr->Name, displacement);
701-
strlcat(scrap, symbuf, scrapSize);
700+
strlcat(scrap, symbuf, ARRAY_SIZE(scrap));
702701
}
703702
} else {
704-
strlcat(scrap, " *", scrapSize);
703+
strlcat(scrap, " *", ARRAY_SIZE(scrap));
705704
}
706-
strlcat(scrap, "\r\n", scrapSize);
705+
strlcat(scrap, "\r\n", ARRAY_SIZE(scrap));
707706
}
708707
}
709708
Add_Txt(scrap);

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ void RegistryClass::Save_Registry_Values(HKEY key, char *path, INIClass *ini)
367367
{
368368
int index = 0;
369369
long result = ERROR_SUCCESS;
370-
const int saveNameSize = 512;
371-
char save_name[saveNameSize];
370+
char save_name[512];
372371

373372
while (result == ERROR_SUCCESS) {
374373
unsigned long type = 0;
@@ -387,7 +386,7 @@ void RegistryClass::Save_Registry_Values(HKEY key, char *path, INIClass *ini)
387386
*/
388387
case REG_DWORD:
389388
strcpy(save_name, "DWORD_");
390-
strlcat(save_name, value_name, saveNameSize);
389+
strlcat(save_name, value_name, ARRAY_SIZE(save_name));
391390
ini->Put_Int(path, save_name, *((unsigned long*)data));
392391
break;
393392

@@ -396,7 +395,7 @@ void RegistryClass::Save_Registry_Values(HKEY key, char *path, INIClass *ini)
396395
*/
397396
case REG_SZ:
398397
strcpy(save_name, "STRING_");
399-
strlcat(save_name, value_name, saveNameSize);
398+
strlcat(save_name, value_name, ARRAY_SIZE(save_name));
400399
ini->Put_String(path, save_name, (char*)data);
401400
break;
402401

@@ -405,7 +404,7 @@ void RegistryClass::Save_Registry_Values(HKEY key, char *path, INIClass *ini)
405404
*/
406405
case REG_BINARY:
407406
strcpy(save_name, "BIN_");
408-
strlcat(save_name, value_name, saveNameSize);
407+
strlcat(save_name, value_name, ARRAY_SIZE(save_name));
409408
ini->Put_UUBlock(path, save_name, (char*)data, data_size);
410409
break;
411410

@@ -470,11 +469,10 @@ void RegistryClass::Save_Registry_Tree(char *path, INIClass *ini)
470469
/*
471470
** See if there are sub keys.
472471
*/
473-
const int newKeyPathSize = 512;
474-
char new_key_path[newKeyPathSize];
472+
char new_key_path[512];
475473
strcpy(new_key_path, path);
476-
strlcat(new_key_path, "\\", newKeyPathSize);
477-
strlcat(new_key_path, name, newKeyPathSize);
474+
strlcat(new_key_path, "\\", ARRAY_SIZE(new_key_path));
475+
strlcat(new_key_path, name, ARRAY_SIZE(new_key_path));
478476

479477
unsigned long num_subs = 0;
480478
unsigned long num_values = 0;
@@ -553,8 +551,7 @@ void RegistryClass::Load_Registry(const char *filename, char *old_path, char *ne
553551
ini.Load(file);
554552

555553
int old_path_len = strlen(old_path);
556-
const int pathSize = 1024;
557-
char path[pathSize];
554+
char path[1024];
558555
char string[1024];
559556
unsigned char buffer[8192];
560557

@@ -570,7 +567,7 @@ void RegistryClass::Load_Registry(const char *filename, char *old_path, char *ne
570567
strcpy(path, new_path);
571568
char *cut = strstr(section_name, old_path);
572569
if (cut) {
573-
strlcat(path, cut + old_path_len, pathSize);
570+
strlcat(path, cut + old_path_len, ARRAY_SIZE(path));
574571
}
575572

576573
/*
@@ -695,11 +692,10 @@ void RegistryClass::Delete_Registry_Tree(char *path)
695692
/*
696693
** See if there are sub keys.
697694
*/
698-
const int newKeyPathSize = 512;
699-
char new_key_path[newKeyPathSize];
695+
char new_key_path[512];
700696
strcpy(new_key_path, path);
701-
strlcat(new_key_path, "\\", newKeyPathSize);
702-
strlcat(new_key_path, name, newKeyPathSize);
697+
strlcat(new_key_path, "\\", ARRAY_SIZE(new_key_path));
698+
strlcat(new_key_path, name, ARRAY_SIZE(new_key_path));
703699

704700
unsigned long num_subs = 0;
705701
unsigned long num_values = 0;

Core/Libraries/Source/debug/debug_debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool Debug::AssertDone(void)
347347
"time being (stops logging this assertion as well).";
348348
char *help=(char *)DebugAllocMemory(ioBuffer[curType].used+strlen(addInfo)+1);
349349
strcpy(help,ioBuffer[curType].buffer+82);
350-
strlcat(help,addInfo, sizeof(help));
350+
strlcat(help, addInfo, sizeof(help));
351351

352352
// First hit? Then do a stack trace
353353
if (curFrameEntry->hits==1)

0 commit comments

Comments
 (0)