[PATCH 3/3] wcsmbs: Ensure wcstr worst-case linear execution time (BZ 23865)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Feb 20 13:16:43 GMT 2024
On 20/02/24 10:01, Alexander Monakov wrote:
>
> On Tue, 20 Feb 2024, Adhemerval Zanella Netto wrote:
>
>>>> wchar_t *
>>>> wcsstr (const wchar_t *haystack, const wchar_t *needle)
>>>> {
>>> any issue with just doing?
>>> ```
>>> memmem(haystack, sizeof(wchar_t) * wcslen(haystack), needle,
>>> sizeof(wchar_t) * wcslen(needle))
>>> ```
>>
>> None at all, in fact this is a better simplification. I will update the
>> patch.
>
> What guarantees that memmem is not going to return a pointer
> into the middle of a wide char?
>
> (neither does strstr defer to memmem, avoiding strlen(haystack)
> when there's an early match)
My understanding is the interface should be composable since memmem
should be agnostic to the input, although it might not have the best
performance (which I really don't care for wcsstr, the idea is just to
remove the quadratic behavior). Do you have an example where it would
fail?
More information about the Libc-alpha
mailing list