[Scummvm-cvs-logs] SF.net SVN: scummvm:[44520] scummvm/trunk/common/str.cpp

wjpalenstijn at users.sourceforge.net wjpalenstijn at users.sourceforge.net
Thu Oct 1 16:47:53 CEST 2009


Revision: 44520
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44520&view=rev
Author:   wjpalenstijn
Date:     2009-10-01 14:47:52 +0000 (Thu, 01 Oct 2009)

Log Message:
-----------
Fix Common::String::printf in MSVC

Modified Paths:
--------------
    scummvm/trunk/common/str.cpp

Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp	2009-10-01 12:41:21 UTC (rev 44519)
+++ scummvm/trunk/common/str.cpp	2009-10-01 14:47:52 UTC (rev 44520)
@@ -447,7 +447,21 @@
 	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 {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list