Skip to content

Commit 5d54b3c

Browse files
committed
Trim UTF8 buffer to size after encoding
1 parent 90eab32 commit 5d54b3c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/builtins.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3524,7 +3524,9 @@ function utf16ToUtf8(str: string) : Uint8Array {
35243524
result[utf8Length++] = 0x80 + (codePoint&0x3F);
35253525
}
35263526
}
3527-
return result.subarray(0, utf8Length);
3527+
let trimmed = new Uint8Array(utf8Length);
3528+
for (let i: i32 = 0; i < utf8Length; ++i) trimmed[i] = result[i];
3529+
return trimmed;
35283530
}
35293531

35303532
// memory.dataUTF8(value) -> usize

0 commit comments

Comments
 (0)