[PATCH] libs/wine/string.c: Always return (int)written

Jonathan Vollebregt jnvsor at gmail.com
Wed Dec 17 05:54:42 CST 2014


No: http://msdn.microsoft.com/en-us/library/1kt27hek.aspx#returnValueToggle

>  vsnprintf ,_vsnprintf, and _vsnwprintf return the number of characters written if the number of characters to write is less than or equal to count; if the number of characters to write is greater than count, these functions return -1 indicating that output has been truncated. The return value does not include the terminating null, if one is written.
>
> 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.

On 12/17/2014 12:47 PM, Hugh McMaster wrote:
> Both GCC and Windows versions of vsnprintf return the number of chars that would be written to a given buffer when vsnprintf(NULL, 0, fmt, va_args) is called.
>
> Wine currently returns -1, which is incorrect.
>
> Also, if there is a short buffer, that is, buffer <= len, not only is any output truncated, but the return value is the number of chars that would be written if the buffer had sufficient space.
>
> Here, Wine returns -1, which is, again, incorrect.
>
> In all cases, the return value should be the number of chars written or the number of chars that would be written if the buffer has sufficient space.



More information about the wine-devel mailing list