From da52a66de1ddc384c66da9bf7dec87ce06c78fd1 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Sat, 14 Sep 2024 11:50:04 +0200 Subject: [PATCH] Cleanup old bytes after update --- .../kotlin/nl/astraeus/tba/SlicedByteArray.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/nl/astraeus/tba/SlicedByteArray.kt b/src/commonMain/kotlin/nl/astraeus/tba/SlicedByteArray.kt index 0d24260..1b62bae 100644 --- a/src/commonMain/kotlin/nl/astraeus/tba/SlicedByteArray.kt +++ b/src/commonMain/kotlin/nl/astraeus/tba/SlicedByteArray.kt @@ -1,5 +1,7 @@ package nl.astraeus.tba +import kotlin.math.min + class SlicedByteArray( val data: ByteArray, val offset: Int, @@ -129,6 +131,11 @@ class SlicedByteArray( } this.setShort(offset + index, bytes.size.toShort()) bytes.copyInto(data, offset + index + 2) + data.fill( + 0, + offset + index + 2 + bytes.size, + offset + index + maxLength + ) } fun setClob(index: Int, value: String, maxLength: Int) { @@ -138,6 +145,11 @@ class SlicedByteArray( } this.setInt(offset + index, bytes.size) bytes.copyInto(data, offset + index + 4) + data.fill( + 0, + offset + index + 4 + bytes.size, + offset + index + maxLength + ) } fun setBlob(index: Int, bytes: SlicedByteArray, maxLength: Int) { @@ -145,7 +157,12 @@ class SlicedByteArray( throw IllegalArgumentException("Blob is too long") } this.setInt(offset + index, bytes.size) - bytes.copyInto(data, offset + index + 4, maxLength) + bytes.copyInto(data, offset + index + 4, bytes.size) + data.fill( + 0, + offset + index + 4 + bytes.size, + offset + index + maxLength + ) } companion object {