From: Dmitry Volyntsev Date: Thu, 22 Mar 2018 12:05:06 +0000 (+0300) Subject: Fixed function frame alignment on 32bits platforms. X-Git-Tag: 0.2.0~17 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=456111b595a7046d4a9bb5516137c601d42bbd29;p=njs.git Fixed function frame alignment on 32bits platforms. --- diff --git a/njs/njs_function.c b/njs/njs_function.c index 52486e8b..6606614f 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -237,6 +237,14 @@ njs_function_frame_alloc(njs_vm_t *vm, size_t size) size_t spare_size, chunk_size; njs_native_frame_t *frame; + /* + * The size value must be aligned to njs_value_t because vm->top_frame + * may point to frame->free and vm->top_frame is used as a base pointer + * in njs_vm_continuation() which is expected to return pointers aligned + * to njs_value_t. + */ + size = nxt_align_size(size, sizeof(njs_value_t)); + spare_size = vm->top_frame->free_size; if (nxt_fast_path(size <= spare_size)) { diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index fb555b86..ed6528df 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -2975,6 +2975,9 @@ static njs_unit_test_t njs_test[] = "a.forEach(function(v, i, a) { a[i+3] = a.length }); a"), nxt_string("1,2,3,3,4,5") }, + { nxt_string("function f() { var c; [1].forEach(function(v) { c })}; f()"), + nxt_string("undefined") }, + { nxt_string("var a = [1,2,3]; var s = { sum: 0 };" "[].forEach.call(a, function(v, i, a) { this.sum += v }, s);" "s.sum"),