Skip to content

Commit fb487d0

Browse files
committed
refactor: Verify array size, fix constness, and improve order of enum values of strings lists
1 parent 783bdb7 commit fb487d0

File tree

96 files changed

+378
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+378
-261
lines changed

Core/GameEngine/Include/Common/AudioEventInfo.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ enum AudioType CPP_11(: Int)
4848
AT_SoundEffect
4949
};
5050

51-
extern const char *theAudioPriorityNames[];
51+
extern const char* const theAudioPriorityNames[];
5252
enum AudioPriority CPP_11(: Int)
5353
{
5454
AP_LOWEST,
5555
AP_LOW,
5656
AP_NORMAL,
5757
AP_HIGH,
58-
AP_CRITICAL
58+
AP_CRITICAL,
59+
60+
AP_COUNT
5961
};
6062

61-
extern const char *theSoundTypeNames[];
63+
extern const char *const theSoundTypeNames[];
6264
enum SoundType CPP_11(: Int)
6365
{
6466
ST_UI = 0x0001,
@@ -72,7 +74,7 @@ enum SoundType CPP_11(: Int)
7274
ST_EVERYONE = 0x0100,
7375
};
7476

75-
extern const char *theAudioControlNames[];
77+
extern const char *const theAudioControlNames[];
7678
enum AudioControl CPP_11(: Int)
7779
{
7880
AC_LOOP = 0x0001,

Core/GameEngine/Include/GameClient/ClientRandomValue.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ class GameClientRandomVariable
6868
*/
6969
enum DistributionType
7070
{
71-
CONSTANT, UNIFORM, GAUSSIAN, TRIANGULAR, LOW_BIAS, HIGH_BIAS
71+
CONSTANT, UNIFORM, GAUSSIAN, TRIANGULAR, LOW_BIAS, HIGH_BIAS,
72+
DISTRIBUTION_COUNT
7273
};
7374

74-
static const char *DistributionTypeNames[];
75+
static const char *const DistributionTypeNames[];
7576

7677
/// define the range of random values, and the distribution of values
7778
void setRange( Real low, Real high, DistributionType type = UNIFORM );

Core/GameEngine/Include/GameLogic/LogicRandomValue.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ class GameLogicRandomVariable
6868
*/
6969
enum DistributionType
7070
{
71-
CONSTANT, UNIFORM, GAUSSIAN, TRIANGULAR, LOW_BIAS, HIGH_BIAS
71+
CONSTANT, UNIFORM, GAUSSIAN, TRIANGULAR, LOW_BIAS, HIGH_BIAS,
72+
DISTRIBUTION_COUNT
7273
};
7374

74-
static const char *DistributionTypeNames[];
75+
static const char *const DistributionTypeNames[];
7576

7677
/// define the range of random values, and the distribution of values
7778
void setRange( Real low, Real high, DistributionType type = UNIFORM );

Core/GameEngine/Source/Common/INI/INIAudioEventInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void parsePitchShift( INI* ini, void *instance, void *store, const void*
179179

180180
// STATIC DEFINIITIONS ////////////////////////////////////////////////////////////////////////////
181181

182-
const char *theAudioPriorityNames[] =
182+
const char *const theAudioPriorityNames[] =
183183
{
184184
"LOWEST",
185185
"LOW",
@@ -188,8 +188,9 @@ const char *theAudioPriorityNames[] =
188188
"CRITICAL",
189189
NULL
190190
};
191+
static_assert(ARRAY_SIZE(theAudioPriorityNames) == AP_COUNT + 1, "Incorrect array size");
191192

192-
const char *theSoundTypeNames[] =
193+
const char *const theSoundTypeNames[] =
193194
{
194195
"UI",
195196
"WORLD",
@@ -203,7 +204,7 @@ const char *theSoundTypeNames[] =
203204
NULL
204205
};
205206

206-
const char *theAudioControlNames[] =
207+
const char *const theAudioControlNames[] =
207208
{
208209
"LOOP",
209210
"RANDOM",

Core/GameEngine/Source/Common/RandomValue.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ DEBUG_LOG(( "%d: GetGameAudioRandomValueReal = %f, %s line %d",
350350
// GameClientRandomVariable
351351
//
352352

353-
/*static*/ const char *GameClientRandomVariable::DistributionTypeNames[] =
353+
const char *const GameClientRandomVariable::DistributionTypeNames[] =
354354
{
355355
"CONSTANT", "UNIFORM", "GAUSSIAN", "TRIANGULAR", "LOW_BIAS", "HIGH_BIAS", NULL
356356
};
357+
static_assert(ARRAY_SIZE(GameClientRandomVariable::DistributionTypeNames) == GameClientRandomVariable::DISTRIBUTION_COUNT + 1, "Incorrect array size");
357358

358359
/**
359360
define the range of random values, and the distribution of values
@@ -395,10 +396,11 @@ Real GameClientRandomVariable::getValue( void ) const
395396
// GameLogicRandomVariable
396397
//
397398

398-
/*static*/ const char *GameLogicRandomVariable::DistributionTypeNames[] =
399+
const char *const GameLogicRandomVariable::DistributionTypeNames[] =
399400
{
400401
"CONSTANT", "UNIFORM", "GAUSSIAN", "TRIANGULAR", "LOW_BIAS", "HIGH_BIAS", NULL
401402
};
403+
static_assert(ARRAY_SIZE(GameLogicRandomVariable::DistributionTypeNames) == GameLogicRandomVariable::DISTRIBUTION_COUNT + 1, "Incorrect array size");
402404

403405
/**
404406
define the range of random values, and the distribution of values

Core/Libraries/Source/WWVegas/WW3D2/rendobj.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,6 @@ template<class T> class DynamicVectorClass;
8585
// "unreferenced formal parameter"
8686
#pragma warning(disable : 4100)
8787

88-
#ifdef DEFINE_W3DANIMMODE_NAMES
89-
static const char* TheAnimModeNames[] =
90-
{
91-
"MANUAL",
92-
"LOOP",
93-
"ONCE",
94-
"LOOP_PINGPONG",
95-
"LOOP_BACKWARDS",
96-
"ONCE_BACKWARDS",
97-
NULL
98-
};
99-
#endif
100-
101-
10288
//////////////////////////////////////////////////////////////////////////////////
10389
// RenderObjClass
10490
// This is the interface for all objects that get rendered by WW3D.
@@ -336,6 +322,8 @@ class RenderObjClass : public RefCountClass , public PersistClass, public MultiL
336322
ANIM_MODE_LOOP_PINGPONG,
337323
ANIM_MODE_LOOP_BACKWARDS, //make sure only backwards playing animations after this one
338324
ANIM_MODE_ONCE_BACKWARDS,
325+
326+
ANIM_MODE_COUNT
339327
};
340328

341329
virtual void Set_Animation( void ) { }
@@ -653,6 +641,19 @@ WWINLINE bool RenderObjClass::Is_Transform_Identity_No_Validity_Check() const
653641
}
654642

655643

644+
#ifdef DEFINE_W3DANIMMODE_NAMES
645+
static const char* const TheAnimModeNames[] =
646+
{
647+
"MANUAL",
648+
"LOOP",
649+
"ONCE",
650+
"LOOP_PINGPONG",
651+
"LOOP_BACKWARDS",
652+
"ONCE_BACKWARDS",
653+
NULL
654+
};
655+
static_assert(ARRAY_SIZE(TheAnimModeNames) == RenderObjClass::ANIM_MODE_COUNT + 1, "Incorrect array size");
656+
#endif
656657

657658

658659
#endif

Core/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static unsigned FreeCount;
9595
** Name for each memory category. I'm padding the array with some "undefined" strings in case
9696
** someone forgets to set the name when adding a new category.
9797
*/
98-
static const char * _MemoryCategoryNames[] =
98+
static const char *const _MemoryCategoryNames[] =
9999
{
100100
"UNKNOWN",
101101
"Geometry",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static StackWalkType _StackWalk = NULL;
138138
static SymFunctionTableAccessType _SymFunctionTableAccess = NULL;
139139
static SymGetModuleBaseType _SymGetModuleBase = NULL;
140140

141-
static char const *ImagehelpFunctionNames[] =
141+
static char const *const ImagehelpFunctionNames[] =
142142
{
143143
"SymCleanup",
144144
"SymGetSymFromAddr",

Core/Libraries/Source/WWVegas/WWLib/WWCommon.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121
#include "stringex.h"
2222

23+
24+
// This macro serves as a general way to determine the number of elements within an array.
25+
#ifndef ARRAY_SIZE
26+
#define ARRAY_SIZE(x) int(sizeof(x)/sizeof(x[0]))
27+
#endif
28+
29+
2330
#if defined(_MSC_VER) && _MSC_VER < 1300
2431
typedef unsigned MemValueType;
2532
#else

Core/Libraries/Source/WWVegas/WWLib/always.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,6 @@ template <class T> T max(T a,T b)
254254
#define NULL 0
255255
#endif
256256

257-
/**********************************************************************
258-
** This macro serves as a general way to determine the number of elements
259-
** within an array.
260-
*/
261-
#ifndef ARRAY_SIZE
262-
#define ARRAY_SIZE(x) int(sizeof(x)/sizeof(x[0]))
263-
#endif
264257

265258
#ifndef size_of
266259
#define size_of(typ,id) sizeof(((typ*)0)->id)

0 commit comments

Comments
 (0)