summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-02-17 13:55:08 +0000
committerrubidium <rubidium@openttd.org>2010-02-17 13:55:08 +0000
commit1b0e78c588b94b1a1dc1ab533576804585dd7a86 (patch)
tree01c255e93cc96944279b1c4912cb6a4e1810b469
parentfa6942a4fa9ee2d7b8bd24ddbc40cd54f239f3c1 (diff)
downloadopenttd-1b0e78c588b94b1a1dc1ab533576804585dd7a86.tar.xz
(svn r19148) -Fix [FS#3627]: [v]seprintf should return the number of added characters excluding '\0' on truncation (adf88)
-rw-r--r--src/string.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 2bd747535..b6e40b7b3 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -32,9 +32,9 @@
*/
static int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
{
- if (str >= last) return 0;
- size_t size = last - str + 1;
- return min((int)size, vsnprintf(str, size, format, ap));
+ ptrdiff_t diff = last - str;
+ if (diff < 0) return 0;
+ return min((int)diff, vsnprintf(str, diff + 1, format, ap));
}
void ttd_strlcat(char *dst, const char *src, size_t size)