re: Properly handle negative start/end values.

pull/14179/head
Jared Hancock 2024-03-28 09:16:50 -05:00
rodzic 8c28d63538
commit f72327165f
1 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -210,15 +210,18 @@ static mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
if (was_compiled && n_args > 2) {
// Arg #2 is starting-pos
size_t startpos = mp_obj_get_int(args[2]);
if (startpos >= len) {
mp_int_t startpos = mp_obj_get_int(args[2]);
if (startpos > (mp_int_t) len) {
startpos = len;
}
else if (startpos < 0) {
startpos = 0;
}
subj.begin += startpos;
if (n_args > 3) {
// Arg #3 is ending-pos
size_t endpos = mp_obj_get_int(args[3]);
if (endpos > len) {
mp_int_t endpos = mp_obj_get_int(args[3]);
if (endpos > (mp_int_t) len) {
endpos = len;
}
else if (endpos < startpos) {