Skip to content

Commit 0e1bc63

Browse files
authored
[GEN][ZH] Demote throw to assert in AsciiString::format_va, UnicodeString::format_va (#835)
1 parent b10267d commit 0e1bc63

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,23 +371,24 @@ void AsciiString::format(const char* format, ...)
371371
// -----------------------------------------------------
372372
void AsciiString::format_va(const AsciiString& format, va_list args)
373373
{
374-
validate();
375-
char buf[MAX_FORMAT_BUF_LEN];
376-
if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format.str(), args) < 0)
377-
throw ERROR_OUT_OF_MEMORY;
378-
set(buf);
379-
validate();
374+
format_va(format.str(), args);
380375
}
381376

382377
// -----------------------------------------------------
383378
void AsciiString::format_va(const char* format, va_list args)
384379
{
385380
validate();
386381
char buf[MAX_FORMAT_BUF_LEN];
387-
if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args) < 0)
388-
throw ERROR_OUT_OF_MEMORY;
389-
set(buf);
390-
validate();
382+
const int result = _vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args);
383+
if (result >= 0)
384+
{
385+
set(buf);
386+
validate();
387+
}
388+
else
389+
{
390+
DEBUG_ASSERTCRASH(false, ("AsciiString::format_va failed with code:%d format:\"%s\"", result, format));
391+
}
391392
}
392393

393394
// -----------------------------------------------------

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,24 @@ void UnicodeString::format(const WideChar* format, ...)
308308
// -----------------------------------------------------
309309
void UnicodeString::format_va(const UnicodeString& format, va_list args)
310310
{
311-
validate();
312-
WideChar buf[MAX_FORMAT_BUF_LEN];
313-
if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format.str(), args) < 0)
314-
throw ERROR_OUT_OF_MEMORY;
315-
set(buf);
316-
validate();
311+
format_va(format.str(), args);
317312
}
318313

319314
// -----------------------------------------------------
320315
void UnicodeString::format_va(const WideChar* format, va_list args)
321316
{
322317
validate();
323318
WideChar buf[MAX_FORMAT_BUF_LEN];
324-
if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args) < 0)
325-
throw ERROR_OUT_OF_MEMORY;
326-
set(buf);
327-
validate();
319+
const int result = _vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args);
320+
if (result >= 0)
321+
{
322+
set(buf);
323+
validate();
324+
}
325+
else
326+
{
327+
DEBUG_ASSERTCRASH(false, ("UnicodeString::format_va failed with code:%d", result));
328+
}
328329
}
329330

330331
//-----------------------------------------------------------------------------

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,24 @@ void AsciiString::format(const char* format, ...)
284284
// -----------------------------------------------------
285285
void AsciiString::format_va(const AsciiString& format, va_list args)
286286
{
287-
validate();
288-
char buf[MAX_FORMAT_BUF_LEN];
289-
if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format.str(), args) < 0)
290-
throw ERROR_OUT_OF_MEMORY;
291-
set(buf);
292-
validate();
287+
format_va(format.str(), args);
293288
}
294289

295290
// -----------------------------------------------------
296291
void AsciiString::format_va(const char* format, va_list args)
297292
{
298293
validate();
299294
char buf[MAX_FORMAT_BUF_LEN];
300-
if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args) < 0)
301-
throw ERROR_OUT_OF_MEMORY;
302-
set(buf);
303-
validate();
295+
const int result = _vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args);
296+
if (result >= 0)
297+
{
298+
set(buf);
299+
validate();
300+
}
301+
else
302+
{
303+
DEBUG_ASSERTCRASH(false, ("AsciiString::format_va failed with code:%d format:\"%s\"", result, format));
304+
}
304305
}
305306

306307
// -----------------------------------------------------

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,24 @@ void UnicodeString::format(const WideChar* format, ...)
308308
// -----------------------------------------------------
309309
void UnicodeString::format_va(const UnicodeString& format, va_list args)
310310
{
311-
validate();
312-
WideChar buf[MAX_FORMAT_BUF_LEN];
313-
if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format.str(), args) < 0)
314-
throw ERROR_OUT_OF_MEMORY;
315-
set(buf);
316-
validate();
311+
format_va(format.str(), args);
317312
}
318313

319314
// -----------------------------------------------------
320315
void UnicodeString::format_va(const WideChar* format, va_list args)
321316
{
322317
validate();
323318
WideChar buf[MAX_FORMAT_BUF_LEN];
324-
if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args) < 0)
325-
throw ERROR_OUT_OF_MEMORY;
326-
set(buf);
327-
validate();
319+
const int result = _vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args);
320+
if (result >= 0)
321+
{
322+
set(buf);
323+
validate();
324+
}
325+
else
326+
{
327+
DEBUG_ASSERTCRASH(false, ("UnicodeString::format_va failed with code:%d", result));
328+
}
328329
}
329330

330331
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)