summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-01-29 17:12:07 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-01-29 17:12:07 -0800
commit9ec15cf362ac5df76e2021282489ab414dfd6fd6 (patch)
tree3eccd4bd57ee01e6c5a0f41426aa709318c1ddf7
parent1cf76c3293fdf8e0326384c39696df844d8d6aed (diff)
downloadbinaryen-9ec15cf362ac5df76e2021282489ab414dfd6fd6.tar.gz
binaryen-9ec15cf362ac5df76e2021282489ab414dfd6fd6.tar.bz2
binaryen-9ec15cf362ac5df76e2021282489ab414dfd6fd6.zip
don't let ceil in binary memory size computation let us get to UINT_MAX which can overflow
-rw-r--r--src/wasm-binary.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index c448f73f4..5d0c41fba 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -396,12 +396,12 @@ public:
if (wasm->memory.initial == 0) { // XXX diverge from v8, 0 means 0, 1 and above are powers of 2 starting at 0
o << int8_t(0);
} else {
- o << int8_t(ceil(log2(wasm->memory.initial)) + 1);
+ o << int8_t(std::min(ceil(log2(wasm->memory.initial)), 31.0) + 1); // up to 31 bits, don't let ceil get us to UINT_MAX which can overflow
}
if (wasm->memory.max == 0) {
o << int8_t(0);
} else {
- o << int8_t(ceil(log2(wasm->memory.max)) + 1);
+ o << int8_t(std::min(ceil(log2(wasm->memory.max)), 31.0) + 1);
}
o << int8_t(1); // export memory
}