diff options
-rw-r--r-- | src/jsifier.js | 4 | ||||
-rwxr-xr-x | tests/runner.py | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index b3c2af1d..1d18f292 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -765,6 +765,10 @@ function JSify(data, functionsOnly, givenFunctions) { } switch (impl) { case VAR_NATIVIZED: + if (isNumber(item.ident)) { + // Direct write to a memory address; this may be an intentional segfault, if not, it is a bug in the source + return 'throw "fault on write to ' + item.ident + '";'; + } return item.ident + '=' + value + ';'; // We have the actual value here break; case VAR_EMULATED: diff --git a/tests/runner.py b/tests/runner.py index d6731ed5..1856016f 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -2856,6 +2856,16 @@ def process(filename): extra_emscripten_args=['-H', 'libc/time.h']) #extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/langinfo.h,libc/time.h']) + def test_intentional_fault(self): + # Some programs intentionally segfault themselves, we should compile that into a throw + src = r''' + int main () { + *(volatile char *)0 = 0; + return 0; + } + ''' + self.do_run(src, 'fault on write to 0') + def test_statics(self): # static initializers save i16 but load i8 for some reason if Settings.SAFE_HEAP: |