diff options
-rw-r--r-- | common/debug.cpp | 13 | ||||
-rw-r--r-- | common/textconsole.cpp | 9 |
2 files changed, 10 insertions, 12 deletions
diff --git a/common/debug.cpp b/common/debug.cpp index dbbb204deb..0dae344bb2 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -107,18 +107,13 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel) { #ifndef DISABLE_TEXT_CONSOLE static void debugHelper(const char *s, va_list va, bool caret = true) { - char buf[STRINGBUFLEN]; + Common::String buf = Common::String::vformat(s, va); - vsnprintf(buf, STRINGBUFLEN, s, va); - buf[STRINGBUFLEN-1] = '\0'; - - if (caret) { - buf[STRINGBUFLEN-2] = '\0'; - strcat(buf, "\n"); - } + if (caret) + buf += '\n'; if (g_system) - g_system->logMessage(LogMessageType::kDebug, buf); + g_system->logMessage(LogMessageType::kDebug, buf.c_str()); // TODO: Think of a good fallback in case we do not have // any OSystem yet. } diff --git a/common/textconsole.cpp b/common/textconsole.cpp index f2325ac9ad..ffa42e63a0 100644 --- a/common/textconsole.cpp +++ b/common/textconsole.cpp @@ -46,14 +46,14 @@ void setErrorHandler(ErrorHandler handler) { #ifndef DISABLE_TEXT_CONSOLE void warning(const char *s, ...) { - char buf[STRINGBUFLEN]; + Common::String output; va_list va; va_start(va, s); - vsnprintf(buf, STRINGBUFLEN, s, va); + output = Common::String::vformat(s, va); va_end(va); - Common::String output = Common::String::format("WARNING: %s!\n", buf); + output = "WARNING: " + output + "!\n"; if (g_system) g_system->logMessage(LogMessageType::kWarning, output.c_str()); @@ -64,6 +64,9 @@ void warning(const char *s, ...) { #endif void NORETURN_PRE error(const char *s, ...) { + // We don't use String::vformat here, as that require + // using the heap, and that might be impossible at this + // point, e.g. if the error was an "out-of-memory" error. char buf_input[STRINGBUFLEN]; char buf_output[STRINGBUFLEN]; va_list va; |