msvcrt: Fix error handling in _mbsupr_s_l.

This commit is contained in:
Piotr Caban 2022-10-19 13:41:44 +02:00 committed by Alexandre Julliard
parent 71144728cf
commit 25bbc7e996
2 changed files with 7 additions and 10 deletions

View file

@ -2194,15 +2194,12 @@ unsigned char* CDECL _mbsupr(unsigned char* s)
*/
int CDECL _mbsupr_s_l(unsigned char* s, size_t len, _locale_t locale)
{
unsigned char *p = s;
if (!s && !len)
{
return 0;
}
else if (!s || !len)
{
*_errno() = EINVAL;
if (!MSVCRT_CHECK_PMT(s && len))
return EINVAL;
}
if (get_mbcinfo()->ismbcodepage)
{
@ -2225,12 +2222,12 @@ int CDECL _mbsupr_s_l(unsigned char* s, size_t len, _locale_t locale)
*s = _toupper_l(*s, locale);
}
if (*s)
if (!MSVCRT_CHECK_PMT(len))
{
*s = '\0';
*_errno() = EINVAL;
*p = 0;
return EINVAL;
}
*s = 0;
return 0;
}

View file

@ -2879,7 +2879,7 @@ static void test__mbsupr_s(void)
memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
errno = EBADF;
ret = p_mbsupr_s(buffer, 4);
ret = p_mbsupr_s(buffer, sizeof("abcdefgh") - 1);
ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);