use stringToUTF8() not writeAsciiToMemory()

This commit is contained in:
cs8425 2022-05-18 14:39:21 +08:00
parent fcc312abd3
commit 005cd56829

View File

@ -1,8 +1,9 @@
module.exports = (Core, args) => { module.exports = (Core, args) => {
const argsPtr = Core._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT); const argsPtr = Core._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
args.forEach((s, idx) => { args.forEach((s, idx) => {
const buf = Core._malloc(s.length + 1); const sz = s.length*4 + 1;
Core.writeAsciiToMemory(s, buf); const buf = Core._malloc(sz);
Core.stringToUTF8(s, buf, sz);
Core.setValue(argsPtr + (Uint32Array.BYTES_PER_ELEMENT * idx), buf, 'i32'); Core.setValue(argsPtr + (Uint32Array.BYTES_PER_ELEMENT * idx), buf, 'i32');
}); });
return [args.length, argsPtr]; return [args.length, argsPtr];