(svn r8089) -[win32] MS-borkedness: All *nprintf functions are broken, but we didn't test to fix it ourselves when 'len = count'.
authorDarkvater
Sat, 13 Jan 2007 13:06:18 +0000
changeset 5630 2bbfa6ea3545
parent 5629 6c255b78703f
child 5631 fd4e111c7ce2
(svn r8089) -[win32] MS-borkedness: All *nprintf functions are broken, but we didn't test to fix it ourselves when 'len = count'.
src/string.cpp
--- a/src/string.cpp	Sat Jan 13 10:38:58 2007 +0000
+++ b/src/string.cpp	Sat Jan 13 13:06:18 2007 +0000
@@ -160,11 +160,16 @@
 }
 
 #ifdef _MSC_VER
+/* *nprintf broken, not POSIX compliant, MSDN description
+ * - If len < count, then len characters are stored in buffer, a null-terminator is appended, and len is returned.
+ * - If len = count, then len characters are stored in buffer, no null-terminator is appended, and len is returned.
+ * - If len > count, then count characters are stored in buffer, no null-terminator is appended, and a negative value is returned
+ */
 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap)
 {
 	int ret;
 	ret = _vsnprintf(str, size, format, ap);
-	if (ret < 0) str[size - 1] = '\0';
+	if (ret < 0 || ret == 0) str[size - 1] = '\0';
 	return ret;
 }
 #endif /* _MSC_VER */