aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/corruptionCheck.js16
-rw-r--r--src/settings.js2
-rwxr-xr-xtests/runner.py3
3 files changed, 13 insertions, 8 deletions
diff --git a/src/corruptionCheck.js b/src/corruptionCheck.js
index ce670401..9c8794cd 100644
--- a/src/corruptionCheck.js
+++ b/src/corruptionCheck.js
@@ -2,7 +2,7 @@
// See settings.js, CORRUPTION_CHECK
var CorruptionChecker = {
- BUFFER_FACTOR: {{{ CORRUPTION_CHECK }}},
+ BUFFER_FACTOR: Math.round({{{ CORRUPTION_CHECK }}}),
ptrs: {},
checks: 0,
@@ -19,6 +19,7 @@ var CorruptionChecker = {
} });
},
malloc: function(size) {
+ CorruptionChecker.checkAll();
assert(size > 0); // some mallocs accept zero - fix your code if you want to use this tool
var allocation = CorruptionChecker.realMalloc(size*(1+2*CorruptionChecker.BUFFER_FACTOR));
var ptr = allocation + size*CorruptionChecker.BUFFER_FACTOR;
@@ -29,7 +30,12 @@ var CorruptionChecker = {
return ptr;
},
free: function(ptr) {
- CorruptionChecker.checkPtr(ptr, true);
+ CorruptionChecker.checkAll();
+ var size = CorruptionChecker.ptrs[ptr];
+ assert(size);
+ var allocation = ptr - size*CorruptionChecker.BUFFER_FACTOR;
+ delete CorruptionChecker.ptrs[ptr];
+ CorruptionChecker.realFree(allocation);
},
canary: function(x) {
return (x + (x << 3) + (x&75) - (x&47))&255;
@@ -45,16 +51,12 @@ var CorruptionChecker = {
}
CorruptionChecker.checks++;
},
- checkPtr: function(ptr, free) {
+ checkPtr: function(ptr) {
var size = CorruptionChecker.ptrs[ptr];
assert(size);
var allocation = ptr - size*CorruptionChecker.BUFFER_FACTOR;
CorruptionChecker.checkBuffer(allocation, size*CorruptionChecker.BUFFER_FACTOR);
CorruptionChecker.checkBuffer(allocation + size*(1+CorruptionChecker.BUFFER_FACTOR), size*CorruptionChecker.BUFFER_FACTOR);
- if (free) {
- delete CorruptionChecker.ptrs[ptr];
- CorruptionChecker.realFree(allocation);
- }
},
checkAll: function() {
for (var ptr in CorruptionChecker.ptrs) {
diff --git a/src/settings.js b/src/settings.js
index 74176914..d036822f 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -142,7 +142,7 @@ var CORRUPTION_CHECK = 0; // When enabled, will emit a buffer area at the beginn
// 0 means not enabled, higher values mean the size of the
// buffer areas as a multiple of the allocated area (so
// 1 means 100%, or buffer areas equal to allocated area,
- // both before and after).
+ // both before and after). This must be an integer.
var LABEL_DEBUG = 0; // 1: Print out functions as we enter them
// 2: Also print out each label as we enter it
diff --git a/tests/runner.py b/tests/runner.py
index aad97db9..8f716719 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7186,6 +7186,9 @@ def process(filename):
self.do_run(src, '''AD:-1,1''', build_ll_hook=self.do_autodebug)
def test_corruption(self):
+ if Settings.ASM_JS: return self.skip('cannot use corruption checks in asm')
+ if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2 for actual test')
+
Settings.CORRUPTION_CHECK = 1
src = r'''