From 5c2f302294afe819adbb225d6698fc5a5f8f3f74 Mon Sep 17 00:00:00 2001 From: Jurriaan Mous Date: Mon, 24 Feb 2025 13:56:39 +0100 Subject: [PATCH] Expand ScanRange checks with returning false if keyBeforeStart or keyOutOfRange with empty arrays. --- .../datastore/scanRange/ScanRange.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/src/commonMain/kotlin/maryk/core/processors/datastore/scanRange/ScanRange.kt b/core/src/commonMain/kotlin/maryk/core/processors/datastore/scanRange/ScanRange.kt index 4ce8546a..7226aae8 100644 --- a/core/src/commonMain/kotlin/maryk/core/processors/datastore/scanRange/ScanRange.kt +++ b/core/src/commonMain/kotlin/maryk/core/processors/datastore/scanRange/ScanRange.kt @@ -16,14 +16,22 @@ data class ScanRange internal constructor( ) { /** Checks if [key] is before start of this scan range */ fun keyBeforeStart(key: ByteArray, offset: Int = 0, length: Int = key.size - offset) = - start.compareDefinedTo(key, offset, length).let { - if (startInclusive) it > 0 else it >= 0 + if (start.isEmpty()) { + false + } else { + start.compareDefinedTo(key, offset, length).let { + if (startInclusive) it > 0 else it >= 0 + } } - /** Checks if [key] is after the end of this range start of this scan range */ + /** Checks if [key] is after the end of this range end of this scan range */ fun keyOutOfRange(key: ByteArray, offset: Int = 0, length: Int = key.size - offset) = end?.let { - end.compareDefinedTo(key, offset, length).let { - if (endInclusive) it < 0 else it <= 0 + if (end.isEmpty()) { + false + } else { + end.compareDefinedTo(key, offset, length).let { + if (endInclusive) it < 0 else it <= 0 + } } } == true