Skip to content

Commit d25e411

Browse files
alex28shSpace Team
authored andcommitted
[Wasm] Fix byte encoding for Latin1 (KT-78998)
1 parent bfa9fba commit d25e411

File tree

2 files changed

+3
-3
lines changed
  • compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm
  • libraries/stdlib/wasm/builtins/kotlin

2 files changed

+3
-3
lines changed

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/ConstantData.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ConstantDataCharArray(val value: List<WasmSymbol<Char>>, val fitsLatin1: B
9393

9494
override fun dump(indent: String, startAddress: Int): String {
9595
if (value.isEmpty()) return ""
96-
return "${addressToString(startAddress)}: $indent i16[] : ${value.map { it.owner }.toCharArray().contentToString()} ;;\n"
96+
return "${addressToString(startAddress)}: $indent i${8 * sizeInBytes}[] : ${value.map { it.owner }.toCharArray().contentToString()} ;;\n"
9797
}
9898

9999
private val bytesPerChar = if (fitsLatin1) BYTE_SIZE_BYTES else CHAR_SIZE_BYTES
@@ -143,7 +143,7 @@ fun Int.toLittleEndianBytes(to: ByteArray, offset: Int) {
143143
}
144144

145145
fun Char.toLittleEndianBytes(to: ByteArray, offset: Int, fitsLatin1: Boolean) {
146-
to[offset] = (this.code and 0xFF).toByte()
146+
to[offset] = this.code.toByte()
147147
if (!fitsLatin1) {
148148
to[offset + 1] = (this.code ushr Byte.SIZE_BITS).toByte()
149149
}

libraries/stdlib/wasm/builtins/kotlin/String.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ internal fun stringLiteralLatin1(poolId: Int): String {
186186
val bytes = array_new_data0<WasmByteArray>(startAddress, length)
187187
val chars = WasmCharArray(length)
188188
for (i in 0..<length) {
189-
val chr = bytes.get(i).toInt().toChar()
189+
val chr = bytes.get(i).toUByte().toInt().toChar()
190190
chars.set(i, chr)
191191
}
192192

0 commit comments

Comments
 (0)