aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-10-01 14:47:52 +0000
committerWillem Jan Palenstijn2009-10-01 14:47:52 +0000
commitddea9a5bda91189988e8f1f6025f8e90aec433c7 (patch)
treeafe9c1a233dffda3215cdb3fc3e7931cc3a4098f
parent6e462c900287a8abd9132a4716153346a3681ba9 (diff)
downloadscummvm-rg350-ddea9a5bda91189988e8f1f6025f8e90aec433c7.tar.gz
scummvm-rg350-ddea9a5bda91189988e8f1f6025f8e90aec433c7.tar.bz2
scummvm-rg350-ddea9a5bda91189988e8f1f6025f8e90aec433c7.zip
Fix Common::String::printf in MSVC
svn-id: r44520
-rw-r--r--common/str.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 0d00cd9378..c51c544556 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -447,7 +447,21 @@ String String::printf(const char *fmt, ...) {
int len = vsnprintf(output._str, _builtinCapacity, fmt, va);
va_end(va);
- if (len < (int)_builtinCapacity) {
+ if (len == -1) {
+ // MSVC doesn't return the size the full string would take up.
+ // Try increasing the size of the string until it fits.
+
+ // We assume MSVC failed to output the correct, null-terminated string
+ // if the return value is either -1 or size.
+ int size = _builtinCapacity;
+ do {
+ size *= 2;
+ output.ensureCapacity(size-1, false);
+ va_start(va, fmt);
+ len = vsnprintf(output._str, size, fmt, va);
+ va_end(va);
+ } while (len == -1 || len >= size);
+ } else if (len < (int)_builtinCapacity) {
// vsnprintf succeeded
output._size = len;
} else {