From 25bb40e66866fc6505ef6362beb5c4945a3759b9 Mon Sep 17 00:00:00 2001 From: Satoshi Otomakan Date: Mon, 23 Dec 2024 12:07:19 +0100 Subject: [PATCH] [KMP]: Fix `COpaquePointer?.readTwBytes()` function extension panic on iOS --- .../iosMain/kotlin/com/trustwallet/core/ByteArrayExt.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kotlin/wallet-core-kotlin/src/iosMain/kotlin/com/trustwallet/core/ByteArrayExt.kt b/kotlin/wallet-core-kotlin/src/iosMain/kotlin/com/trustwallet/core/ByteArrayExt.kt index ec5923272a1..eca16bc383b 100644 --- a/kotlin/wallet-core-kotlin/src/iosMain/kotlin/com/trustwallet/core/ByteArrayExt.kt +++ b/kotlin/wallet-core-kotlin/src/iosMain/kotlin/com/trustwallet/core/ByteArrayExt.kt @@ -8,8 +8,12 @@ import kotlinx.cinterop.COpaquePointer import kotlinx.cinterop.readBytes import kotlinx.cinterop.toCValues -internal fun COpaquePointer?.readTwBytes(): ByteArray? = - TWDataBytes(this)?.readBytes(TWDataSize(this).toInt()) +internal fun COpaquePointer?.readTwBytes(): ByteArray? { + if (this == null) { + return null; + } + return TWDataBytes(this)?.readBytes(TWDataSize(this).toInt()) +} @OptIn(ExperimentalUnsignedTypes::class) internal fun ByteArray?.toTwData(): COpaquePointer? =