Fix out of bounds when trying to get a pointer to empty array

This commit is contained in:
Ugljesa Jovanovic committed 2021-07-27 11:46:39 +02:00
1 parent 310e86695d
commit 9f11aa8af9
3 files changed
+161 -1

No files matched your search

@@ -11,4 +11,10 @@ import kotlinx.cinterop.toCPointer
* ugljesa.jovanovic@ionspin.com
* on 27-Aug-2020
*/
fun Pinned<UByteArray>.toPtr() : CPointer<UByteVar>? = addressOf(0)
fun Pinned<UByteArray>.toPtr() : CPointer<UByteVar>? {
return try {
addressOf(0)
} catch (outOfBounds : ArrayIndexOutOfBoundsException) {
null
}
}