emscripten-core / emscripten-core/emscripten

compiling 64bit webassembly returning an empty string using embind returns a string with "0" in it.

Open
#23,914 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Please include the following in your bug report:

**Version of emscripten/emsdk:**
4.0.2

The code in libembind.js that handles the fromWireType for a std::string does
var a = new Array(length);

In 64 bit builds length is a BigInt so this creates an array with 1 element in it with the value of length not a 0 length string.
This can be fixed by this patch:-

--- libembind.js.orig 2025-03-13 12:49:21.000000000 +0000
+++ libembind.js 2025-03-13 12:50:28.582019800 +0000
@@ -528,7 +528,7 @@
}
}
} else {
- var a = new Array(length);
+ var a = new Array(Number(length));
for (var i = 0; i < length; ++i) {
a[i] = String.fromCharCode(HEAPU8[payload + i]);
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.