summaryrefslogtreecommitdiff
path: root/src/wasm.h
diff options
context:
space:
mode:
authorJF Bastien <github@jfbastien.com>2016-05-03 14:05:44 -0700
committerJF Bastien <github@jfbastien.com>2016-05-03 14:05:44 -0700
commitb6ec3620376a8b9cf7cedfe7f61fd4c943e0275b (patch)
tree635a4938c01a235747c6b76cd364ca223e74e540 /src/wasm.h
parent09153904803c628393a8ff65c1791d3bc57c756b (diff)
downloadbinaryen-b6ec3620376a8b9cf7cedfe7f61fd4c943e0275b.tar.gz
binaryen-b6ec3620376a8b9cf7cedfe7f61fd4c943e0275b.tar.bz2
binaryen-b6ec3620376a8b9cf7cedfe7f61fd4c943e0275b.zip
Fix shift UB (#429)
Getting close to finishing #404.
Diffstat (limited to 'src/wasm.h')
-rw-r--r--src/wasm.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/wasm.h b/src/wasm.h
index dcad171a0..f9d0cb129 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -530,22 +530,22 @@ public:
}
Literal shl(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 << other.i32);
- case WasmType::i64: return Literal(i64 << other.i64);
+ case WasmType::i32: return Literal(uint32_t(i32) << (other.i32 & 0x1f));
+ case WasmType::i64: return Literal(uint64_t(i64) << (other.i64 & 0x3f));
default: WASM_UNREACHABLE();
}
}
Literal shrS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 >> other.i32);
- case WasmType::i64: return Literal(i64 >> other.i64);
+ case WasmType::i32: return Literal(i32 >> (other.i32 & 0x1f));
+ case WasmType::i64: return Literal(i64 >> (other.i64 & 0x3f));
default: WASM_UNREACHABLE();
}
}
Literal shrU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) >> uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) >> uint64_t(other.i64));
+ case WasmType::i32: return Literal(uint32_t(i32) >> uint32_t(other.i32 & 0x1f));
+ case WasmType::i64: return Literal(uint64_t(i64) >> uint64_t(other.i64 & 0x3f));
default: WASM_UNREACHABLE();
}
}