From 67f37bad8de600c6137b38f7d835cf87cea772d9 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Fri, 19 May 2017 17:44:33 +0300 Subject: [PATCH] Fixed bug in strings comparison --- runtime/src/main/cpp/KString.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runtime/src/main/cpp/KString.cpp b/runtime/src/main/cpp/KString.cpp index c001d676392..6187e87a2e1 100644 --- a/runtime/src/main/cpp/KString.cpp +++ b/runtime/src/main/cpp/KString.cpp @@ -744,10 +744,14 @@ OBJ_GETTER(CreateStringFromUtf8, const char* utf8, uint32_t lengthBytes) { // String.kt KInt Kotlin_String_compareTo(KString thiz, KString other) { - return memcmp( + int result = memcmp( CharArrayAddressOfElementAt(thiz, 0), CharArrayAddressOfElementAt(other, 0), (thiz->count_ < other->count_ ? thiz->count_ : other->count_) * sizeof(KChar)); + if (result != 0) return result; + int diff = thiz->count_ - other->count_; + if (diff == 0) return 0; + return diff < 0 ? -1 : 1; } KChar Kotlin_String_get(KString thiz, KInt index) {