diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-02-25 15:41:42 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-02-25 15:41:42 -0500 |
commit | 875426c1f23c5a2dbacb3c947ffe82ee71b28720 (patch) | |
tree | c34b3fde64366fa25023f0cb4a153249d33dfbfe /src/parseTools.js | |
parent | a0141bb1999899c82492a7a839a892dc53405acc (diff) |
ensure input to HEAP[U]8 is an int
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index ae5831ae..357d33a1 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -103,6 +103,11 @@ function isNiceIdent(ident, loose) { } } +function isJSVar(ident) { + return /^\(?[$_]?[\w$_\d ]*\)+$/.test(ident); + +} + function isStructPointerType(type) { // This test is necessary for clang - in llvm-gcc, we // could check for %struct. The downside is that %1 can @@ -988,7 +993,8 @@ function getHeapOffset(offset, type, forceAsm) { if (shifts != 0) { return '(' + offset + '>>' + shifts + ')'; } else { - return offset; + // we need to guard against overflows here, HEAP[U]8 expects a guaranteed int + return isJSVar(offset) ? offset : '(' + offset + '|0)'; } } } |