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

Hugh McMaster hugh.mcmaster at outlook.com
Fri Dec 19 05:35:50 CST 2014


Sorry, I didn't see your message as it was sent to wine-patches.

On Thursday, 18 Dec 2014 18:09:01 +0100, Jonathan Vollebregt wrote:

>> If buffer or format is NULL, or if count is less than or equal to zero, these functions invoke the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, these functions return -1 and set errno to EINVAL.

>This doc says that vsnprintf *should* always return -1 given your example.
Yes, MSDN does say that.

>Is there a test that shows the MSDN docs are wrong?
I'm not sure if Wine has one, but I'll check. Running multiple tests with Visual Studio 2013 on Windows 7 64-bit returns the number of chars that would be written for vsnprintf(NULL, 0, fmt, args).

-1 is returned in cases when "the number of characters to write is greater than count". So some examples would be vsnprintf(valid buffer, 0, fmt, args) or vsnprintf(very small buffer, 8, fmt, args).

>On 12/18/2014 11:57 AM, Hugh McMaster wrote:
>> 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 --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20141219/0b1b7956/attachment.html>


More information about the wine-devel mailing list