From 8b7eedc180804cc8eb47f90cbdfc07bca2862ab7 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 15 Sep 2020 17:40:08 +0200 Subject: [PATCH] msvcrt: Fix _vs{w,n}printf_c function when terminating character doesn't fit into buffer. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcr100/msvcr100.spec | 8 ++++---- dlls/msvcr110/msvcr110.spec | 8 ++++---- dlls/msvcr120/msvcr120.spec | 8 ++++---- dlls/msvcr80/msvcr80.spec | 8 ++++---- dlls/msvcr90/msvcr90.spec | 8 ++++---- dlls/msvcrt/msvcrt.spec | 8 ++++---- dlls/msvcrt/tests/printf.c | 5 +++++ dlls/msvcrt/wcs.c | 37 +++++++++++++++++++++++++++++++++++++ 8 files changed, 66 insertions(+), 24 deletions(-) diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index a396ee38a76..f507406d52d 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -1454,8 +1454,8 @@ @ cdecl _vscwprintf_p(wstr ptr) MSVCRT__vscwprintf_p @ cdecl _vscwprintf_p_l(wstr ptr ptr) MSVCRT__vscwprintf_p_l @ cdecl -norelay _vsnprintf(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l +@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf_c +@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_c_l @ cdecl _vsnprintf_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l @ cdecl _vsnprintf_s(ptr long long str ptr) MSVCRT_vsnprintf_s @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr) MSVCRT_vsnprintf_s_l @@ -1468,8 +1468,8 @@ @ cdecl _vsprintf_p_l(ptr long str ptr ptr) MSVCRT_vsprintf_p_l @ cdecl _vsprintf_s_l(ptr long str ptr ptr) MSVCRT_vsprintf_s_l @ cdecl _vswprintf(ptr wstr ptr) MSVCRT_vswprintf -@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vsnwprintf -@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vsnwprintf_l +@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vswprintf_c +@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_c_l @ cdecl _vswprintf_l(ptr wstr ptr ptr) MSVCRT_vswprintf_l @ cdecl _vswprintf_p(ptr long wstr ptr) MSVCRT__vswprintf_p @ cdecl _vswprintf_p_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_p_l diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index b91a5df3ab4..7423a1ccd6a 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -1811,8 +1811,8 @@ @ cdecl _vscwprintf_p(wstr ptr) MSVCRT__vscwprintf_p @ cdecl _vscwprintf_p_l(wstr ptr ptr) MSVCRT__vscwprintf_p_l @ cdecl -norelay _vsnprintf(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l +@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf_c +@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_c_l @ cdecl _vsnprintf_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l @ cdecl _vsnprintf_s(ptr long long str ptr) MSVCRT_vsnprintf_s @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr) MSVCRT_vsnprintf_s_l @@ -1825,8 +1825,8 @@ @ cdecl _vsprintf_p_l(ptr long str ptr ptr) MSVCRT_vsprintf_p_l @ cdecl _vsprintf_s_l(ptr long str ptr ptr) MSVCRT_vsprintf_s_l @ cdecl _vswprintf(ptr wstr ptr) MSVCRT_vswprintf -@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vsnwprintf -@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vsnwprintf_l +@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vswprintf_c +@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_c_l @ cdecl _vswprintf_l(ptr wstr ptr ptr) MSVCRT_vswprintf_l @ cdecl _vswprintf_p(ptr long wstr ptr) MSVCRT__vswprintf_p @ cdecl _vswprintf_p_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_p_l diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 1d23526d805..64b4e2d625c 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -1829,8 +1829,8 @@ @ cdecl _vscwprintf_p(wstr ptr) MSVCRT__vscwprintf_p @ cdecl _vscwprintf_p_l(wstr ptr ptr) MSVCRT__vscwprintf_p_l @ cdecl -norelay _vsnprintf(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l +@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf_c +@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_c_l @ cdecl _vsnprintf_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l @ cdecl _vsnprintf_s(ptr long long str ptr) MSVCRT_vsnprintf_s @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr) MSVCRT_vsnprintf_s_l @@ -1843,8 +1843,8 @@ @ cdecl _vsprintf_p_l(ptr long str ptr ptr) MSVCRT_vsprintf_p_l @ cdecl _vsprintf_s_l(ptr long str ptr ptr) MSVCRT_vsprintf_s_l @ cdecl _vswprintf(ptr wstr ptr) MSVCRT_vswprintf -@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vsnwprintf -@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vsnwprintf_l +@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vswprintf_c +@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_c_l @ cdecl _vswprintf_l(ptr wstr ptr ptr) MSVCRT_vswprintf_l @ cdecl _vswprintf_p(ptr long wstr ptr) MSVCRT__vswprintf_p @ cdecl _vswprintf_p_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_p_l diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index 4050750123a..9c4e56d0c34 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -1133,8 +1133,8 @@ @ cdecl _vscwprintf_p(wstr ptr) MSVCRT__vscwprintf_p @ cdecl _vscwprintf_p_l(wstr ptr ptr) MSVCRT__vscwprintf_p_l @ cdecl -norelay _vsnprintf(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l +@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf_c +@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_c_l @ cdecl _vsnprintf_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l @ cdecl _vsnprintf_s(ptr long long str ptr) MSVCRT_vsnprintf_s @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr) MSVCRT_vsnprintf_s_l @@ -1147,8 +1147,8 @@ @ cdecl _vsprintf_p_l(ptr long str ptr ptr) MSVCRT_vsprintf_p_l @ cdecl _vsprintf_s_l(ptr long str ptr ptr) MSVCRT_vsprintf_s_l @ cdecl _vswprintf(ptr wstr ptr) MSVCRT_vswprintf -@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vsnwprintf -@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vsnwprintf_l +@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vswprintf_c +@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_c_l @ cdecl _vswprintf_l(ptr wstr ptr ptr) MSVCRT_vswprintf_l @ cdecl _vswprintf_p(ptr long wstr ptr) MSVCRT__vswprintf_p @ cdecl _vswprintf_p_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_p_l diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index 5208d3e5f35..1b7e3810d8d 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -1109,8 +1109,8 @@ @ cdecl _vscwprintf_p(wstr ptr) MSVCRT__vscwprintf_p @ cdecl _vscwprintf_p_l(wstr ptr ptr) MSVCRT__vscwprintf_p_l @ cdecl -norelay _vsnprintf(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l +@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf_c +@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_c_l @ cdecl _vsnprintf_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l @ cdecl _vsnprintf_s(ptr long long str ptr) MSVCRT_vsnprintf_s @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr) MSVCRT_vsnprintf_s_l @@ -1123,8 +1123,8 @@ @ cdecl _vsprintf_p_l(ptr long str ptr ptr) MSVCRT_vsprintf_p_l @ cdecl _vsprintf_s_l(ptr long str ptr ptr) MSVCRT_vsprintf_s_l @ cdecl _vswprintf(ptr wstr ptr) MSVCRT_vswprintf -@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vsnwprintf -@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vsnwprintf_l +@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vswprintf_c +@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_c_l @ cdecl _vswprintf_l(ptr wstr ptr ptr) MSVCRT_vswprintf_l @ cdecl _vswprintf_p(ptr long wstr ptr) MSVCRT__vswprintf_p @ cdecl _vswprintf_p_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_p_l diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index 2dc9c87e57a..e7be7d6982a 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -1063,8 +1063,8 @@ @ cdecl _vscwprintf_l(wstr ptr ptr) MSVCRT__vscwprintf_l @ cdecl _vscwprintf_p_l(wstr ptr ptr) MSVCRT__vscwprintf_p_l @ cdecl -norelay _vsnprintf(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf -@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l +@ cdecl _vsnprintf_c(ptr long str ptr) MSVCRT_vsnprintf_c +@ cdecl _vsnprintf_c_l(ptr long str ptr ptr) MSVCRT_vsnprintf_c_l @ cdecl _vsnprintf_l(ptr long str ptr ptr) MSVCRT_vsnprintf_l @ cdecl _vsnprintf_s(ptr long long str ptr) MSVCRT_vsnprintf_s @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr) MSVCRT_vsnprintf_s_l @@ -1077,8 +1077,8 @@ @ cdecl _vsprintf_p_l(ptr long str ptr ptr) MSVCRT_vsprintf_p_l @ cdecl _vsprintf_s_l(ptr long str ptr ptr) MSVCRT_vsprintf_s_l @ cdecl _vswprintf(ptr wstr ptr) MSVCRT_vswprintf -@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vsnwprintf -@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vsnwprintf_l +@ cdecl _vswprintf_c(ptr long wstr ptr) MSVCRT_vswprintf_c +@ cdecl _vswprintf_c_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_c_l @ cdecl _vswprintf_l(ptr wstr ptr ptr) MSVCRT_vswprintf_l @ cdecl _vswprintf_p_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_p_l @ cdecl _vswprintf_s_l(ptr long wstr ptr ptr) MSVCRT_vswprintf_s_l diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c index 84da6578fea..bbcdd476c6c 100644 --- a/dlls/msvcrt/tests/printf.c +++ b/dlls/msvcrt/tests/printf.c @@ -917,6 +917,11 @@ static void test_vswprintf(void) ok(ret == 10, "got %d, expected 10\n", ret); ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf)); + memset(buf, 'x', sizeof(buf)); + ret = _vswprintf_c_wrapper(buf, 10, format, number, 123); + ok(ret == -1, "got %d, expected -1\n", ret); + ok(!wcscmp(buf, L"number 12"), "buf = %s\n", wine_dbgstr_w(buf)); + memset(buf, 0, sizeof(buf)); ret = _vswprintf_c_l_wrapper(buf, 20, format, NULL, number, 123); ok(ret == 10, "got %d, expected 10\n", ret); diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 78d522152ea..7ceaa5c7413 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -1010,6 +1010,24 @@ int CDECL MSVCRT_vsnprintf_s( char *str, MSVCRT_size_t sizeOfBuffer, return MSVCRT_vsnprintf_s_l(str,sizeOfBuffer, count, format, NULL, valist); } +/********************************************************************* + * _vsnprintf_c_l (MSVCRT.@) + */ +int CDECL MSVCRT_vsnprintf_c_l(char *str, MSVCRT_size_t len, const char *format, + MSVCRT__locale_t locale, __ms_va_list valist) +{ + return MSVCRT_vsnprintf_s_l_opt(str, len, len, format, 0, locale, valist); +} + +/********************************************************************* + * _vsnprintf_c (MSVCRT.@) + */ +int CDECL MSVCRT_vsnprintf_c(char *str, MSVCRT_size_t len, + const char *format, __ms_va_list valist) +{ + return MSVCRT_vsnprintf_c_l(str, len, format, NULL, valist); +} + #if _MSVCR_VER>=140 /********************************************************************* @@ -1218,6 +1236,25 @@ int CDECL MSVCRT_vsnwprintf_l(MSVCRT_wchar_t *str, MSVCRT_size_t len, return ret; } +/********************************************************************* + * _vswprintf_c_l (MSVCRT.@) + */ +int CDECL MSVCRT_vswprintf_c_l(MSVCRT_wchar_t *str, MSVCRT_size_t len, + const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, + __ms_va_list valist) +{ + return MSVCRT_vsnwprintf_s_l_opt(str, len, len, format, 0, locale, valist); +} + +/********************************************************************* + * _vswprintf_c (MSVCRT.@) + */ +int CDECL MSVCRT_vswprintf_c(MSVCRT_wchar_t *str, MSVCRT_size_t len, + const MSVCRT_wchar_t *format, __ms_va_list valist) +{ + return MSVCRT_vswprintf_c_l(str, len, format, NULL, valist); +} + static int MSVCRT_vswprintf_p_l_opt(MSVCRT_wchar_t *buffer, MSVCRT_size_t length, const MSVCRT_wchar_t *format, DWORD options, MSVCRT__locale_t locale, __ms_va_list args) {