Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
wcsstr fails to find substring in almost all cases.
Steps to reproduce the problem:
const wchar_t* searchRes = wcsstr(L"romrom", L"rom");
assert(searchRes != NULL);
What happened:
assertion failure.
I checked out code from master branch. Here is the problem summary.
wchar_t *wcsstr(const wchar_t *s, const wchar_t *find) {
wchar_t find_c;
//find_c == 'r'
find_c = *find++;
//find points to "om" string here
if (!find_c)
return (wchar_t*)s;
size_t find_len = wcslen(find);
for (;;) {
wchar_t* p = wcschr(s, find_c);
//p points to "romrom" string here
if (p == NULL)
return NULL;
//and now we compare p == "romrom" and find == "om", find_len == 2
if (!wmemcmp(p, find, find_len))
return p;
s = p + 1;
}
return NULL;
}
The fix is
if (!wmemcmp(p+1, find, find_len))
//------------^