diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-11-23 15:37:38 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-11-23 15:37:38 +0100 |
commit | ebbde8f46f75053a6026723c57c09b82d5853377 (patch) | |
tree | 28edb33e64aef2200b888b124d6e7d9ca2185aa2 | |
parent | 1b738e61aeee7bb704859bda3eaadb6d804cd3f0 (diff) |
assert on string operations not exceeding memory
-rw-r--r-- | src/preamble.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/preamble.js b/src/preamble.js index 1c66797b..d2bbc6a4 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -544,6 +544,9 @@ function Pointer_stringify(ptr, /* optional */ length) { var i = 0; var t; while (1) { +#if ASSERTIONS + assert(i < TOTAL_MEMORY); +#endif t = {{{ makeGetValue('ptr', 'i', 'i8', 0, 1) }}}; if (nullTerminated && t == 0) break; ret += utf8.processCChar(t); @@ -750,7 +753,11 @@ function exitRuntime() { function String_len(ptr) { var i = ptr; - while ({{{ makeGetValue('i++', '0', 'i8') }}}) {}; // Note: should be |!= 0|, technically. But this helps catch bugs with undefineds + while ({{{ makeGetValue('i++', '0', 'i8') }}}) { // Note: should be |!= 0|, technically. But this helps catch bugs with undefineds +#if ASSERTIONS + assert(i < TOTAL_MEMORY); +#endif + } return i - ptr - 1; } Module['String_len'] = String_len; |