From: Hugh McMaster Subject: [PATCH] libs/wine/string.c: Duplicate Windows behaviour in vsnprintfW Message-Id: Date: Thu, 18 Dec 2014 21:57:35 +1100 Recent discussions on the wine-devel mailing list conclude that Wine's vsnprintfW must duplicate Windows' vsnprintf behaviourW[1]. Currently, there are two issues. 1. vsnprintfW(NULL, 0, fmt, args). Both Windows and GCC allow these arguments. Both return the number of chars that would be written in this instance. Wine returns -1, which is incorrect. 2. vsnprintfW(some buffer, 0, fmt, args). Both Windows and Wine return -1, but in this case, Wine does this by default. We need to maintain this behaviour. To fix these inconsistencies, we need to add an 'else' block to the check for len (i.e. checking for a non-zero value). Then we check for a NULL pointer. If true, we return (int)written, like Windows and GCC do, because vsnprintfW(NULL, 0, fmt, args) was called. This patch fixes these issues. [1] https://www.winehq.org/pipermail/wine-devel/2014-December/106066.html From 648aeca20176ea9d5c250e78477aca8e8c8140c1 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Thu, 18 Dec 2014 19:46:34 +1100 Subject: [PATCH] libs/wine/string.c: Duplicate Windows behaviour in vsnprintfW --- libs/wine/string.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/wine/string.c b/libs/wine/string.c index f2a9bd3..f0ddaad 100644 --- a/libs/wine/string.c +++ b/libs/wine/string.c @@ -497,6 +497,11 @@ int vsnprintfW(WCHAR *str, size_t len, const WCHAR *format, va_list valist) str--; *str++ = 0; } + else + { + if (!str) + return (int)written; + } /* FIXME: POSIX [v]snprintf() returns the equivalent of written, not -1, on short buffer. */ return written < len ? (int)written : -1; -- 1.9.1