[njs] Fixed function frame alignment on 32bits platforms.

Dmitry Volyntsev xeioex at nginx.com
Thu Mar 22 12:05:26 UTC 2018


details:   http://hg.nginx.org/njs/rev/529c376ec5e2
branches:  
changeset: 466:529c376ec5e2
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Mar 22 15:05:06 2018 +0300
description:
Fixed function frame alignment on 32bits platforms.

diffstat:

 njs/njs_function.c       |  8 ++++++++
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)

diffs (31 lines):

diff -r 750f7c6f071c -r 529c376ec5e2 njs/njs_function.c
--- a/njs/njs_function.c	Wed Mar 21 17:33:13 2018 +0300
+++ b/njs/njs_function.c	Thu Mar 22 15:05:06 2018 +0300
@@ -237,6 +237,14 @@ njs_function_frame_alloc(njs_vm_t *vm, s
     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 -r 750f7c6f071c -r 529c376ec5e2 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Mar 21 17:33:13 2018 +0300
+++ b/njs/test/njs_unit_test.c	Thu Mar 22 15:05:06 2018 +0300
@@ -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"),


More information about the nginx-devel mailing list