mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
Fix an off-by-one error of own memrchr implementation
and make it support `search_len == 0`, just for the case Ref [Bug #20796]
This commit is contained in:
parent
257f78fb67
commit
a83c91dd7a
Notes:
git
2024-10-21 11:41:01 +00:00
1 changed files with 2 additions and 2 deletions
4
string.c
4
string.c
|
@ -4548,9 +4548,9 @@ static void*
|
||||||
memrchr(const char *search_str, int chr, long search_len)
|
memrchr(const char *search_str, int chr, long search_len)
|
||||||
{
|
{
|
||||||
const char *ptr = search_str + search_len;
|
const char *ptr = search_str + search_len;
|
||||||
do {
|
while (ptr > search_str) {
|
||||||
if ((unsigned char)*(--ptr) == chr) return (void *)ptr;
|
if ((unsigned char)*(--ptr) == chr) return (void *)ptr;
|
||||||
} while (ptr >= search_str);
|
}
|
||||||
|
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue