[PATCH] libs/wine/string.c: Duplicate Windows behaviour in vsnprintfW

Hugh McMaster hugh.mcmaster at outlook.com
Thu Dec 18 04:57:35 CST 2014

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stringc-zero-len.patch
Type: application/octet-stream
Size: 818 bytes
Desc: not available
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20141218/6695af87/attachment.obj>

More information about the wine-patches mailing list