Avoid relying on FOR_EACH_TAIL internals in 'Fnthcdr' (bug#81115)

The new FOR_EACH_TAIL code detects simple cycles sooner than the old
code did, leading to integer overflows.

* src/fns.c (Fnthcdr): Avoid integer overflow if cycle is detected
early.
This commit is contained in:
Pip Cet 2026-05-25 11:28:38 +00:00
parent 0bef3c0e87
commit c1eb458d6b

View file

@ -1824,7 +1824,10 @@ DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0,
mpz_export (&iz, NULL, -1, sizeof iz, 0, 0, mpz[0]);
num += iz;
}
num += cycle_length - large_num % cycle_length;
if (num < cycle_length)
num += cycle_length;
num -= large_num % cycle_length;
eassume (num >= 0);
}
num %= cycle_length;