aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2011-03-18 14:42:51 +0100
committerMax Horn2011-06-18 01:36:16 +0200
commitb81207a04ecb5057b2b6efa0f3a6288b6e969aef (patch)
treeef5aaaa273b1812a0e98bf4fcfb1bfa9803c8b05 /common
parentd74e2d3224f7f43daf7bc90018b1b3f40a8c4596 (diff)
downloadscummvm-rg350-b81207a04ecb5057b2b6efa0f3a6288b6e969aef.tar.gz
scummvm-rg350-b81207a04ecb5057b2b6efa0f3a6288b6e969aef.tar.bz2
scummvm-rg350-b81207a04ecb5057b2b6efa0f3a6288b6e969aef.zip
COMMON: Replace some vsnprintf/STRINGBUFLEN uses by vformat
Diffstat (limited to 'common')
-rw-r--r--common/debug.cpp13
-rw-r--r--common/textconsole.cpp9
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;