diff options
-rw-r--r-- | src/pal/src/cruntime/wchar.cpp | 12 | ||||
-rw-r--r-- | src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp | 10 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/pal/src/cruntime/wchar.cpp b/src/pal/src/cruntime/wchar.cpp index 3de065e361..5b466960a6 100644 --- a/src/pal/src/cruntime/wchar.cpp +++ b/src/pal/src/cruntime/wchar.cpp @@ -1194,16 +1194,22 @@ PAL_wcsstr( i = 0; while (1) { - if (*(string + i) == 0 || *(strCharSet + i) == 0) + if (*(strCharSet + i) == 0) { ret = (wchar_16 *) string; goto leave; } - if (*(string + i) != *(strCharSet + i)) + else if (*(string + i) == 0) + { + ret = NULL; + goto leave; + } + else if (*(string + i) != *(strCharSet + i)) { break; } - i++; + + i++; } string++; } diff --git a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp index 8296a74983..16005a9f8e 100644 --- a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp +++ b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp @@ -21,6 +21,7 @@ int __cdecl main(int argc, char *argv[]) WCHAR *key1; WCHAR *key2; WCHAR key3[] = { 0 }; + WCHAR *key4; WCHAR *result; if (PAL_Initialize(argc, argv)) @@ -31,6 +32,7 @@ int __cdecl main(int argc, char *argv[]) string = convert("foo bar baz bar"); key1 = convert("bar"); key2 = convert("Bar"); + key4 = convert("arggggh!"); result = wcsstr(string, key1); if (result != string + 4) @@ -57,6 +59,14 @@ int __cdecl main(int argc, char *argv[]) convertC(key3), string, result); } + result = wcsstr(string, key4); + if (result != nullptr) + { + Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n" + "Expected to get pointer to null, got %#p\n", convertC(string), + convertC(key4), result); + } + PAL_Terminate(); return PASS; } |