Issue #28822: Adjust indices handling of PyUnicode_FindChar().
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 3fdce82..bbda4d8 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9461,16 +9461,12 @@
int direction)
{
int kind;
- Py_ssize_t result;
+ Py_ssize_t len, result;
if (PyUnicode_READY(str) == -1)
return -2;
- if (start < 0 || end < 0) {
- PyErr_SetString(PyExc_IndexError, "string index out of range");
- return -2;
- }
- if (end > PyUnicode_GET_LENGTH(str))
- end = PyUnicode_GET_LENGTH(str);
- if (start >= end)
+ len = PyUnicode_GET_LENGTH(str);
+ ADJUST_INDICES(start, end, len);
+ if (end - start < 1)
return -1;
kind = PyUnicode_KIND(str);
result = findchar(PyUnicode_1BYTE_DATA(str) + kind*start,