diff options
author | Chad Austin <caustin@gmail.com> | 2013-02-25 23:50:32 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:24:12 +0300 |
commit | f7b5f283e123ef2cf892c9e5d8a97cbd9e68349c (patch) | |
tree | c0db232327a8b4547ddd705f8258145b5a2734ee /system | |
parent | 78548810ba0ec6386fc4c7ab1342fe55321dad40 (diff) |
Use length-prefix strings instead of null-terminated strings to support passing strings with embedded nul characters.
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/wire.h | 14 |
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); |