assert on string operations not exceeding memory

This commit is contained in:
Alon Zakai 2012-11-23 15:37:38 +01:00
Родитель 1b738e61ae
Коммит ebbde8f46f
1 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -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;