From 5aaf075af897979fa47600d934565f5cf3231ec6 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Fri, 31 Aug 2018 10:52:08 +0300 Subject: [PATCH] Fix some range checks appeared to be incorrect when index > array.size --- runtime/src/main/cpp/Arrays.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/src/main/cpp/Arrays.cpp b/runtime/src/main/cpp/Arrays.cpp index 523c15ef20f..e244b7d20f1 100644 --- a/runtime/src/main/cpp/Arrays.cpp +++ b/runtime/src/main/cpp/Arrays.cpp @@ -38,8 +38,8 @@ inline void copyImpl(KConstRef thiz, KInt fromIndex, const ArrayHeader* array = thiz->array(); ArrayHeader* destinationArray = destination->array(); if (count < 0 || - fromIndex < 0 || count > array->count_ - fromIndex || - toIndex < 0 || count > destinationArray->count_ - toIndex) { + fromIndex < 0 || static_cast(count) + fromIndex > array->count_ || + toIndex < 0 || static_cast(count) + toIndex > destinationArray->count_) { ThrowArrayIndexOutOfBoundsException(); } mutabilityCheck(destination); @@ -96,8 +96,8 @@ void Kotlin_Array_copyImpl(KConstRef thiz, KInt fromIndex, const ArrayHeader* array = thiz->array(); ArrayHeader* destinationArray = destination->array(); if (count < 0 || - fromIndex < 0 || count > array->count_ - fromIndex || - toIndex < 0 || count > destinationArray->count_ - toIndex) { + fromIndex < 0 || static_cast(count) + fromIndex > array->count_ || + toIndex < 0 || static_cast(count)+ toIndex > destinationArray->count_) { ThrowArrayIndexOutOfBoundsException(); } mutabilityCheck(destination);