aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-04-24 16:52:27 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-04-24 17:46:17 -0700
commit0689e43ae61723dde87ec9a2b6210a349d080b31 (patch)
treec889633c6c7630df5d3423c1d8e40e8a648edd55 /tests
parent13f1516d15c72fe3b2a6ea70a2ab643f1eedd825 (diff)
check function table masks in safe heap mode
Diffstat (limited to 'tests')
-rw-r--r--tests/test_other.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_other.py b/tests/test_other.py
index cdea493a..e4d91ba6 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2710,3 +2710,35 @@ int main()
assert os.path.exists('hello_world.o')
assert os.path.exists('hello_world.bc')
+ def test_bad_function_pointer_cast(self):
+ open('src.cpp', 'w').write(r'''
+#include <stdio.h>
+
+typedef int (*callback) (int, ...);
+
+int impl(int foo) {
+ printf("Hello, world.\n");
+ return 0;
+}
+
+int main() {
+ volatile callback f = (callback) impl;
+ f(0); /* This fails with or without additional arguments. */
+ return 0;
+}
+''')
+
+ for opts in [0, 1, 2]:
+ for safe in [0, 1]:
+ cmd = [PYTHON, EMCC, 'src.cpp', '-O' + str(opts), '-s', 'SAFE_HEAP=' + str(safe)]
+ print cmd
+ Popen(cmd).communicate()
+ output = run_js('a.out.js', stderr=PIPE, full_output=True)
+ if safe:
+ assert 'Function table mask error' in output, output
+ else:
+ if opts == 0:
+ assert 'Invalid function pointer called' in output, output
+ else:
+ assert 'abort()' in output, output
+