Make sure index and count do not overflow for long sequences

Throw an exception immediately before an overflow becomes observable.
Place check to prevent negative index from indexOf, indexOfFirst.
Do not insert overflow checks for arrays, lists, maps and char sequences.

#KT-16097
This commit is contained in:
Ilya Gorbunov
2018-08-09 23:31:31 +03:00
parent c44f62a3d4
commit 357c5be4fb
16 changed files with 252 additions and 58 deletions
@@ -2263,6 +2263,8 @@ public final class kotlin/collections/CollectionsKt {
public static final fun takeLast (Ljava/util/List;I)Ljava/util/List;
public static final fun takeLastWhile (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List;
public static final fun takeWhile (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List;
public static final fun throwCountOverflow ()V
public static final fun throwIndexOverflow ()V
public static final fun toBooleanArray (Ljava/util/Collection;)[Z
public static final fun toByteArray (Ljava/util/Collection;)[B
public static final fun toCharArray (Ljava/util/Collection;)[C