summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJF Bastien <jfb@chromium.org>2016-01-10 19:56:36 -0800
committerJF Bastien <jfb@chromium.org>2016-01-10 19:56:36 -0800
commiteb0444e0870052b8ea8021eb50563a9f4d957486 (patch)
treed2ea8f8c9a43dfee51fc779b9a9c03fb51bc86d4 /src
parent16ed70cb09569b881b6416955000fa7902119264 (diff)
downloadbinaryen-eb0444e0870052b8ea8021eb50563a9f4d957486.tar.gz
binaryen-eb0444e0870052b8ea8021eb50563a9f4d957486.tar.bz2
binaryen-eb0444e0870052b8ea8021eb50563a9f4d957486.zip
Safe integer: assert before converting double to integer.
Diffstat (limited to 'src')
-rw-r--r--src/support/safe_integer.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/support/safe_integer.cpp b/src/support/safe_integer.cpp
index 46057cede..dbe62ca52 100644
--- a/src/support/safe_integer.cpp
+++ b/src/support/safe_integer.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <cassert>
#include <cmath>
#include <limits>
@@ -33,12 +34,14 @@ bool wasm::isSInteger32(double x) {
}
uint32_t wasm::toUInteger32(double x) {
+ assert(isUInteger32(x));
return x < std::numeric_limits<uint32_t>::max()
? x
: std::numeric_limits<uint32_t>::max();
}
int32_t wasm::toSInteger32(double x) {
+ assert(isSInteger32(x));
return x > std::numeric_limits<int32_t>::min() &&
x < std::numeric_limits<int32_t>::max()
? x
@@ -56,12 +59,14 @@ bool wasm::isSInteger64(double x) {
}
uint64_t wasm::toUInteger64(double x) {
+ assert(isUInteger64(x));
return x < (double)std::numeric_limits<uint64_t>::max()
? (uint64_t)x
: std::numeric_limits<uint64_t>::max();
}
int64_t wasm::toSInteger64(double x) {
+ assert(isSInteger64(x));
return x > (double)std::numeric_limits<int64_t>::min() &&
x < (double)std::numeric_limits<int64_t>::max()
? (int64_t)x