Commit 7d94c4f0 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

ntdll: Fix memchr implementation.

parent d44f5434
......@@ -2621,7 +2621,7 @@ void* __cdecl memchr(const void *ptr, int c, size_t n)
{
const unsigned char *p = ptr;
for (p = ptr; n; n--, p++) if (*p == c) return (void *)(ULONG_PTR)p;
for (p = ptr; n; n--, p++) if (*p == (unsigned char)c) return (void *)(ULONG_PTR)p;
return NULL;
}
......
......@@ -72,7 +72,7 @@ void * __cdecl memchr( const void *ptr, int c, size_t n )
{
const unsigned char *p = ptr;
for (p = ptr; n; n--, p++) if (*p == c) return (void *)(ULONG_PTR)p;
for (p = ptr; n; n--, p++) if (*p == (unsigned char)c) return (void *)(ULONG_PTR)p;
return NULL;
}
......
......@@ -65,6 +65,7 @@ static int (__cdecl *p_wcsnicmp)(LPCWSTR,LPCWSTR,int);
static LPWSTR (__cdecl *pwcschr)(LPCWSTR, WCHAR);
static LPWSTR (__cdecl *pwcsrchr)(LPCWSTR, WCHAR);
static void* (__cdecl *pmemchr)(const void*, int, size_t);
static void (__cdecl *pqsort)(void *,size_t,size_t, int(__cdecl *compar)(const void *, const void *) );
static void* (__cdecl *pbsearch)(void *,void*,size_t,size_t, int(__cdecl *compar)(const void *, const void *) );
......@@ -134,6 +135,7 @@ static void InitFunctionPtrs(void)
X(_wcsnicmp);
X(wcschr);
X(wcsrchr);
X(memchr);
X(qsort);
X(bsearch);
X(_snprintf);
......@@ -2035,6 +2037,24 @@ static void test_ctype(void)
}
}
static void test_memchr(void)
{
const char s[] = "ab";
char *r;
r = pmemchr(s, 'z', 2);
ok(!r, "memchr returned %p, expected NULL\n", r);
r = pmemchr(s, 'a', 2);
ok(r == s, "memchr returned %p, expected %p\n", r, s);
r = pmemchr(s, 0x100 + 'a', 2);
ok(r == s, "memchr returned %p, expected %p\n", r, s);
r = pmemchr(s, -0x100 + 'a', 2);
ok(r == s, "memchr returned %p, expected %p\n", r, s);
}
START_TEST(string)
{
InitFunctionPtrs();
......@@ -2066,4 +2086,5 @@ START_TEST(string)
test_sscanf();
test_wctype();
test_ctype();
test_memchr();
}
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