diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-27 04:52:13 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-27 04:52:13 -0700 |
commit | 91975ac3a86e3644503e263d53c1ea870816354a (patch) | |
tree | 9a9e3cbf0a8e2d9ac919d6318dec9126f6c57000 /web/static | |
parent | 44f14e515e111164c552d0f9a9ad8dce38b3d136 (diff) | |
download | dartboat-91975ac3a86e3644503e263d53c1ea870816354a.tar.gz dartboat-91975ac3a86e3644503e263d53c1ea870816354a.tar.xz |
web: malloc c strings explicitly; pass null pointer when empty
Diffstat (limited to 'web/static')
-rw-r--r-- | web/static/dartboat.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 9921cf3..e43488b 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -47,8 +47,20 @@ function promptMsgR(p) { document.getElementById('prompt-msg-r').textContent = UTF8ToString(p); } +function stringToCString(str) { // caller must free + const len = lengthBytesUTF8(str) + 1; + const cstr = _malloc(len); + stringToUTF8(str, cstr, len); + return cstr; +} + function promptHandle(command, data) { - Module.ccall('prompt_handle', null, ['string', 'string'], [command, data]); + const str_c = stringToCString(command); + const str_d = data && stringToCString(data); + _prompt_handle(str_c, str_d); + + _free(str_c); + if (str_d) _free(str_d); } function setKeypad(keypad) { |