mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
py/objstr: In find/rfind, don't crash when end < start.
This commit is contained in:
committed by
Damien George
parent
b9c78425a6
commit
d6cf5c6749
@@ -699,8 +699,13 @@ STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, b
|
||||
end = str_index_to_ptr(self_type, haystack, haystack_len, args[3], true);
|
||||
}
|
||||
|
||||
if (end < start) {
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
const byte *p = find_subbytes(start, end - start, needle, needle_len, direction);
|
||||
if (p == NULL) {
|
||||
out_error:
|
||||
// not found
|
||||
if (is_index) {
|
||||
mp_raise_ValueError("substring not found");
|
||||
|
||||
Reference in New Issue
Block a user