diff --git a/Generals/Code/GameEngine/Source/Common/System/AsciiString.cpp b/Generals/Code/GameEngine/Source/Common/System/AsciiString.cpp index 24995d7b21..255f8c6282 100644 --- a/Generals/Code/GameEngine/Source/Common/System/AsciiString.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/AsciiString.cpp @@ -371,12 +371,7 @@ void AsciiString::format(const char* format, ...) // ----------------------------------------------------- void AsciiString::format_va(const AsciiString& format, va_list args) { - validate(); - char buf[MAX_FORMAT_BUF_LEN]; - if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format.str(), args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + format_va(format.str(), args); } // ----------------------------------------------------- @@ -384,10 +379,16 @@ void AsciiString::format_va(const char* format, va_list args) { validate(); char buf[MAX_FORMAT_BUF_LEN]; - if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + const int result = _vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args); + if (result >= 0) + { + set(buf); + validate(); + } + else + { + DEBUG_ASSERTCRASH(false, ("AsciiString::format_va failed with code:%d format:\"%s\"", result, format)); + } } // ----------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/Common/System/UnicodeString.cpp b/Generals/Code/GameEngine/Source/Common/System/UnicodeString.cpp index 6d7b35d408..1f8aa59a14 100644 --- a/Generals/Code/GameEngine/Source/Common/System/UnicodeString.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/UnicodeString.cpp @@ -308,12 +308,7 @@ void UnicodeString::format(const WideChar* format, ...) // ----------------------------------------------------- void UnicodeString::format_va(const UnicodeString& format, va_list args) { - validate(); - WideChar buf[MAX_FORMAT_BUF_LEN]; - if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format.str(), args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + format_va(format.str(), args); } // ----------------------------------------------------- @@ -321,10 +316,16 @@ void UnicodeString::format_va(const WideChar* format, va_list args) { validate(); WideChar buf[MAX_FORMAT_BUF_LEN]; - if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + const int result = _vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args); + if (result >= 0) + { + set(buf); + validate(); + } + else + { + DEBUG_ASSERTCRASH(false, ("UnicodeString::format_va failed with code:%d", result)); + } } //----------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp index dbdc5b0d55..bae77bb02f 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp @@ -284,12 +284,7 @@ void AsciiString::format(const char* format, ...) // ----------------------------------------------------- void AsciiString::format_va(const AsciiString& format, va_list args) { - validate(); - char buf[MAX_FORMAT_BUF_LEN]; - if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format.str(), args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + format_va(format.str(), args); } // ----------------------------------------------------- @@ -297,10 +292,16 @@ void AsciiString::format_va(const char* format, va_list args) { validate(); char buf[MAX_FORMAT_BUF_LEN]; - if (_vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + const int result = _vsnprintf(buf, sizeof(buf)/sizeof(char)-1, format, args); + if (result >= 0) + { + set(buf); + validate(); + } + else + { + DEBUG_ASSERTCRASH(false, ("AsciiString::format_va failed with code:%d format:\"%s\"", result, format)); + } } // ----------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp index 1fe351c2ad..6115baae1d 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp @@ -308,12 +308,7 @@ void UnicodeString::format(const WideChar* format, ...) // ----------------------------------------------------- void UnicodeString::format_va(const UnicodeString& format, va_list args) { - validate(); - WideChar buf[MAX_FORMAT_BUF_LEN]; - if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format.str(), args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + format_va(format.str(), args); } // ----------------------------------------------------- @@ -321,10 +316,16 @@ void UnicodeString::format_va(const WideChar* format, va_list args) { validate(); WideChar buf[MAX_FORMAT_BUF_LEN]; - if (_vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args) < 0) - throw ERROR_OUT_OF_MEMORY; - set(buf); - validate(); + const int result = _vsnwprintf(buf, sizeof(buf)/sizeof(WideChar)-1, format, args); + if (result >= 0) + { + set(buf); + validate(); + } + else + { + DEBUG_ASSERTCRASH(false, ("UnicodeString::format_va failed with code:%d", result)); + } } //-----------------------------------------------------------------------------