summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-27 18:56:13 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-27 18:56:13 -0800
commit013c4987d4d14047aef036188d8d7bcea693c1cf (patch)
tree73c24acd93516d56ff99513474a296a498bdd591 /src
parente7461ed17e5f0cc9e49ada34b0fb340dce8e9b49 (diff)
downloadbinaryen-013c4987d4d14047aef036188d8d7bcea693c1cf.tar.gz
binaryen-013c4987d4d14047aef036188d8d7bcea693c1cf.tar.bz2
binaryen-013c4987d4d14047aef036188d8d7bcea693c1cf.zip
ensure memory is initialized to 0 in native shell
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-shell.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index b2ba51544..197de545b 100644
--- a/src/binaryen-shell.cpp
+++ b/src/binaryen-shell.cpp
@@ -37,7 +37,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
ShellExternalInterface() : memory(nullptr) {}
void init(Module& wasm) override {
- memory = (char*)malloc(wasm.memory.initial);
+ memory = (char*)calloc(wasm.memory.initial, 1);
// apply memory segments
for (auto segment : wasm.memory.segments) {
memcpy(memory + segment.offset, segment.data, segment.size);
@@ -114,6 +114,9 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
void growMemory(size_t oldSize, size_t newSize) override {
memory = (char*)realloc(memory, newSize);
+ if (newSize > oldSize) {
+ memset(memory + oldSize, 0, newSize - oldSize);
+ }
}
jmp_buf trapState;