mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8314236
: Overflow in Collections.rotate
Co-authored-by: Nikita Sakharin <17588081+nikita-sakharin@users.noreply.github.com> Reviewed-by: shade, smarks
This commit is contained in:
parent
1203e11a8d
commit
3828dc913a
2 changed files with 88 additions and 4 deletions
|
@ -816,15 +816,16 @@ public class Collections {
|
|||
if (distance == 0)
|
||||
return;
|
||||
|
||||
for (int cycleStart = 0, nMoved = 0; nMoved != size; cycleStart++) {
|
||||
int bound = size - distance;
|
||||
for (int cycleStart = 0, nMoved = 0; nMoved < size; cycleStart++) {
|
||||
T displaced = list.get(cycleStart);
|
||||
int i = cycleStart;
|
||||
do {
|
||||
i += distance;
|
||||
if (i >= size)
|
||||
if (i >= bound)
|
||||
i -= size;
|
||||
i += distance;
|
||||
displaced = list.set(i, displaced);
|
||||
nMoved ++;
|
||||
nMoved++;
|
||||
} while (i != cycleStart);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue