Commit c54e0d93 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fix error handling in _mbslwr_s_l.

parent 25bbc7e9
...@@ -2114,15 +2114,12 @@ unsigned char* CDECL _mbslwr(unsigned char* s) ...@@ -2114,15 +2114,12 @@ unsigned char* CDECL _mbslwr(unsigned char* s)
*/ */
int CDECL _mbslwr_s_l(unsigned char* s, size_t len, _locale_t locale) int CDECL _mbslwr_s_l(unsigned char* s, size_t len, _locale_t locale)
{ {
unsigned char *p = s;
if (!s && !len) if (!s && !len)
{
return 0; return 0;
} if (!MSVCRT_CHECK_PMT(s && len))
else if (!s || !len)
{
*_errno() = EINVAL;
return EINVAL; return EINVAL;
}
if (get_mbcinfo()->ismbcodepage) if (get_mbcinfo()->ismbcodepage)
{ {
...@@ -2145,12 +2142,12 @@ int CDECL _mbslwr_s_l(unsigned char* s, size_t len, _locale_t locale) ...@@ -2145,12 +2142,12 @@ int CDECL _mbslwr_s_l(unsigned char* s, size_t len, _locale_t locale)
*s = _tolower_l(*s, locale); *s = _tolower_l(*s, locale);
} }
if (*s) if (!MSVCRT_CHECK_PMT(len))
{ {
*s = '\0'; *p = 0;
*_errno() = EINVAL;
return EINVAL; return EINVAL;
} }
*s = 0;
return 0; return 0;
} }
......
...@@ -2944,7 +2944,7 @@ static void test__mbslwr_s(void) ...@@ -2944,7 +2944,7 @@ static void test__mbslwr_s(void)
memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH")); memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
errno = EBADF; errno = EBADF;
ret = p_mbslwr_s(buffer, 4); ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH") - 1);
ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret); ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment