aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorChad Austin <caustin@gmail.com>2013-02-25 23:50:32 -0800
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:24:12 +0300
commitf7b5f283e123ef2cf892c9e5d8a97cbd9e68349c (patch)
treec0db232327a8b4547ddd705f8258145b5a2734ee /system
parent78548810ba0ec6386fc4c7ab1342fe55321dad40 (diff)
Use length-prefix strings instead of null-terminated strings to support passing strings with embedded nul characters.
Diffstat (limited to 'system')
-rwxr-xr-xsystem/include/emscripten/wire.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h
index dc612e11..10484a61 100755
--- a/system/include/emscripten/wire.h
+++ b/system/include/emscripten/wire.h
@@ -180,12 +180,18 @@ namespace emscripten {
template<>
struct BindingType<std::string> {
- typedef char* WireType;
+ typedef struct {
+ size_t length;
+ char data[1]; // trailing data
+ }* WireType;
static WireType toWireType(const std::string& v) {
- return strdup(v.c_str());
+ WireType wt = (WireType)malloc(sizeof(size_t) + v.length());
+ wt->length = v.length();
+ memcpy(wt->data, v.data(), v.length());
+ return wt;
}
- static std::string fromWireType(char* v) {
- return std::string(v);
+ static std::string fromWireType(WireType v) {
+ return std::string(v->data, v->length);
}
static void destroy(WireType v) {
free(v);