Skip to content

Commit e65006e

Browse files
authored
[GEN][ZH] Demote throw to assert in AsciiString::ensureUniqueBufferOfSize, UnicodeString::ensureUniqueBufferOfSize, Dict::ensureUnique (#861)
1 parent 455dfab commit e65006e

File tree

6 files changed

+6
-18
lines changed

6 files changed

+6
-18
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ Dict::DictPair *Dict::ensureUnique(int numPairsNeeded, Bool preserveData, DictPa
157157
return pairToTranslate;
158158
}
159159

160-
if (numPairsNeeded > MAX_LEN)
161-
throw ERROR_OUT_OF_MEMORY;
162-
163160
Dict::DictPairData* newData = NULL;
164161
if (numPairsNeeded > 0)
165162
{
163+
DEBUG_ASSERTCRASH(numPairsNeeded <= MAX_LEN, ("Dict::ensureUnique exceeds max pairs length %d with requested length %d", MAX_LEN, numPairsNeeded));
166164
int minBytes = sizeof(Dict::DictPairData) + numPairsNeeded*sizeof(Dict::DictPair);
167165
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
168166
// note: be certain to alloc with zero; we'll take advantage of the fact that all-zero

Generals/Code/GameEngine/Source/Common/System/AsciiString.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ void AsciiString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveData
138138
return;
139139
}
140140

141+
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("AsciiString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
141142
int minBytes = sizeof(AsciiStringData) + numCharsNeeded*sizeof(char);
142-
if (minBytes > MAX_LEN)
143-
throw ERROR_OUT_OF_MEMORY;
144-
145143
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
146144
AsciiStringData* newData = (AsciiStringData*)TheDynamicMemoryAllocator->allocateBytesDoNotZero(actualBytes, "STR_AsciiString::ensureUniqueBufferOfSize");
147145
newData->m_refCount = 1;

Generals/Code/GameEngine/Source/Common/System/UnicodeString.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
9494
return;
9595
}
9696

97+
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("UnicodeString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
9798
int minBytes = sizeof(UnicodeStringData) + numCharsNeeded*sizeof(WideChar);
98-
if (minBytes > MAX_LEN)
99-
throw ERROR_OUT_OF_MEMORY;
100-
10199
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
102100
UnicodeStringData* newData = (UnicodeStringData*)TheDynamicMemoryAllocator->allocateBytesDoNotZero(actualBytes, "STR_UnicodeString::ensureUniqueBufferOfSize");
103101
newData->m_refCount = 1;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ Dict::DictPair *Dict::ensureUnique(int numPairsNeeded, Bool preserveData, DictPa
157157
return pairToTranslate;
158158
}
159159

160-
if (numPairsNeeded > MAX_LEN)
161-
throw ERROR_OUT_OF_MEMORY;
162-
163160
Dict::DictPairData* newData = NULL;
164161
if (numPairsNeeded > 0)
165162
{
163+
DEBUG_ASSERTCRASH(numPairsNeeded <= MAX_LEN, ("Dict::ensureUnique exceeds max pairs length %d with requested length %d", MAX_LEN, numPairsNeeded));
166164
int minBytes = sizeof(Dict::DictPairData) + numPairsNeeded*sizeof(Dict::DictPair);
167165
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
168166
// note: be certain to alloc with zero; we'll take advantage of the fact that all-zero

GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ void AsciiString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveData
134134
return;
135135
}
136136

137+
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("AsciiString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
137138
int minBytes = sizeof(AsciiStringData) + numCharsNeeded*sizeof(char);
138-
if (minBytes > MAX_LEN)
139-
throw ERROR_OUT_OF_MEMORY;
140-
141139
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
142140
AsciiStringData* newData = (AsciiStringData*)TheDynamicMemoryAllocator->allocateBytesDoNotZero(actualBytes, "STR_AsciiString::ensureUniqueBufferOfSize");
143141
newData->m_refCount = 1;

GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
9494
return;
9595
}
9696

97+
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("UnicodeString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
9798
int minBytes = sizeof(UnicodeStringData) + numCharsNeeded*sizeof(WideChar);
98-
if (minBytes > MAX_LEN)
99-
throw ERROR_OUT_OF_MEMORY;
100-
10199
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
102100
UnicodeStringData* newData = (UnicodeStringData*)TheDynamicMemoryAllocator->allocateBytesDoNotZero(actualBytes, "STR_UnicodeString::ensureUniqueBufferOfSize");
103101
newData->m_refCount = 1;

0 commit comments

Comments
 (0)