[PATCH v2 3/7] string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp].
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Mon Jan 10 13:09:21 GMT 2022
Hi Florian,
>>> These implementations are incorrect. There may be a mismatch in s1/s2
>>> before invalid memory but no null CHAR / length boundary.
>>
>> This is not true, see
>> eg. https://en.cppreference.com/w/cpp/string/byte/strcmp. Most string
>> functions require that the string is correctly terminated. There are
>> only a few exceptions (memchr IIRC), and several generic
>> implementations use strlen or strnlen before the main loop.
>
> I am not sure if those are bugs. Don't we support non-array usage in
> these functions as an extension? At least for strncmp and strnlen and
> their wide counterparts. C11 is pretty clear that strncmp operates on
> arrays, so this is an extension.
My concern is about being able to read beyond a mismatch (which you have
to anyway when you process more than 1 character per iteration) rather than
reading beyond the end of a string or array.
What do you mean with non-array usage? Reading beyond the size parameter
in a strn* function if a NUL terminator has not been found yet? Or not stopping
at NUL before the size?
Wilco
More information about the Libc-alpha
mailing list