Commit 2af3f320 authored by Bartosz Kosiorek's avatar Bartosz Kosiorek Committed by Alexandre Julliard

msvcrt: Fix _strnicmp and _strnicmp_l implementation.

parent 49d3236d
......@@ -3313,11 +3313,15 @@ int __cdecl _strnicmp_l(const char *s1, const char *s2,
pthreadlocinfo locinfo;
int c1, c2;
if(s1==NULL || s2==NULL)
return _NLSCMPERROR;
if(!count)
return 0;
#if _MSVCR_VER>=80
if(!MSVCRT_CHECK_PMT(s1 && s2 && count <= INT_MAX))
#else
/* Old versions of msvcrt.dll didn't have count <= INT_MAX check */
if(!MSVCRT_CHECK_PMT(s1 && s2))
#endif /* _MSVCR_VER>=140 */
return _NLSCMPERROR;
if(!locale)
locinfo = get_locinfo();
......@@ -3349,7 +3353,7 @@ int __cdecl _strnicmp_l(const char *s1, const char *s2,
*/
int __cdecl _stricmp_l(const char *s1, const char *s2, _locale_t locale)
{
return _strnicmp_l(s1, s2, -1, locale);
return _strnicmp_l(s1, s2, INT_MAX, locale);
}
/*********************************************************************
......@@ -3365,7 +3369,7 @@ int __cdecl _strnicmp(const char *s1, const char *s2, size_t count)
*/
int __cdecl _stricmp(const char *s1, const char *s2)
{
return _strnicmp_l(s1, s2, -1, NULL);
return _strnicmp_l(s1, s2, INT_MAX, NULL);
}
/*********************************************************************
......
......@@ -482,13 +482,31 @@ static void test__strnicmp(void)
SET_EXPECT(invalid_parameter_handler);
errno = 0xdeadbeef;
ret = _strnicmp(str1, NULL, 2);
CHECK_CALLED(invalid_parameter_handler);
ok(ret == _NLSCMPERROR, "got %d.\n", ret);
ok(errno == EINVAL, "Unexpected errno %d.\n", errno);
SET_EXPECT(invalid_parameter_handler);
errno = 0xdeadbeef;
ret = _strnicmp(str1, str2, -1);
todo_wine CHECK_CALLED(invalid_parameter_handler);
todo_wine ok(ret == _NLSCMPERROR, "got %d.\n", ret);
todo_wine ok(errno == EINVAL, "Unexpected errno %d.\n", errno);
CHECK_CALLED(invalid_parameter_handler);
ok(ret == _NLSCMPERROR, "got %d.\n", ret);
ok(errno == EINVAL, "Unexpected errno %d.\n", errno);
ret = _strnicmp(str1, str2, 0);
ok(!ret, "got %d.\n", ret);
ret = _strnicmp(str1, str2, 0x7fffffff);
ok(!ret, "got %d.\n", ret);
/* If numbers of characters to compare is too big return error */
SET_EXPECT(invalid_parameter_handler);
errno = 0xdeadbeef;
ret = _strnicmp(str1, str2, 0x80000000);
CHECK_CALLED(invalid_parameter_handler);
ok(ret == _NLSCMPERROR, "got %d.\n", ret);
ok(errno == EINVAL, "Unexpected errno %d.\n", errno);
}
static void test_wcsnicmp(void)
......
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