diff --git a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmNativeMem.kt b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmNativeMem.kt index 41ddc6e58e1..a1e4818a35e 100644 --- a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmNativeMem.kt +++ b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmNativeMem.kt @@ -51,7 +51,10 @@ object nativeMemUtils { internal class NativeAllocated(override val rawPtr: NativePtr) : NativePointed fun alloc(size: Long, align: Int): NativePointed { - val address = unsafe.allocateMemory(size) + val address = unsafe.allocateMemory( + if (size == 0L) 1L else size // It is a hack: `sun.misc.Unsafe` can't allocate zero bytes + ) + if (address % align != 0L) TODO(align.toString()) return interpretPointed(address) }