Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions web/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ export class CachedCallStack implements Disposable {
* @param data The string content.
*/
allocThenSetArgString(offset: PtrOffset, data: string): void {
const strOffset = this.allocRawBytes(data.length + 1);
this.storeRawBytes(strOffset, StringToUint8Array(data));
const dataUint8: Uint8Array = StringToUint8Array(data);
const strOffset = this.allocRawBytes(dataUint8.length);
this.storeRawBytes(strOffset, dataUint8);
this.addressToSetTargetValue.push([offset, strOffset]);
}
/**
Expand Down
11 changes: 6 additions & 5 deletions web/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ export function isPromise(value: any): boolean {
* @returns The corresponding Uint8Array.
*/
export function StringToUint8Array(str: string): Uint8Array {
const arr = new Uint8Array(str.length + 1);
for (let i = 0; i < str.length; ++i) {
arr[i] = str.charCodeAt(i);
const arr: Uint8Array = new TextEncoder().encode(str);
const resArr = new Uint8Array(arr.length + 1);
for (let i = 0; i < arr.length; ++i) {
resArr[i] = arr[i];
}
arr[str.length] = 0;
return arr;
resArr[arr.length] = 0;
return resArr;
}

/**
Expand Down