在 03/10/2020 05:50 AM, Martin Storsjö 写道:
> According to standard C99, the swprintf and vswprintf functions
> return a negative value if the buffer is insufficient (contrary to
> snprintf). As far as I can read the standard, the contents of the
> buffer in this case is unspecified, but this patch makes it match
> MSVC, which does null terminate it.
> 
> Signed-off-by: Martin Storsjö <[email protected]>
> ---
>  


> diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h
> index 3fde2a6fb..f4e10e2f4 100644
> --- a/mingw-w64-headers/crt/wchar.h
> +++ b/mingw-w64-headers/crt/wchar.h
> @@ -824,7 +824,8 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const 
> wchar_t *__format, __builti
>    __mingw_ovr
>    int __cdecl vsnwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t 
> * __restrict__ format, va_list arg)

`vsnwprintf()` is non-standard. I am not sure which function it should
follow - `_vsnwprintf()` or just `vswprintf()`, but either way, this
name is confusing.

Also, if it is necessary to normalize the return value to `-1` please
use reserved identifiers for local variables such as `__ret`. Likewise
for the other hunk for 'wchar.h'.

>    {
> -    return __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE | 
> UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, s, n, format, NULL, arg);
> +    int ret = __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE, s, n, 
> format, NULL, arg);
> +    return ret < 0 ? -1 : ret;
>    }
>  #endif
>  
> 


-- 
Best regards,
LH_Mouse

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to