]> git.kaiwu.me - njs.git/commitdiff
The "break" and "continue" statements did not work on big endian
authorIgor Sysoev <igor@sysoev.ru>
Sun, 27 Dec 2015 12:23:57 +0000 (15:23 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Sun, 27 Dec 2015 12:23:57 +0000 (15:23 +0300)
platforms.

njs/njs_generator.c
njs/njs_parser.h

index 120ecd994767183272bf444efe81448488833522..f40e493f97ec21d44951ce61cea005b745ffe9d2 100644 (file)
@@ -572,7 +572,7 @@ njs_generate_switch_statement(njs_vm_t *vm, njs_parser_t *parser,
                 return NXT_ERROR;
             }
 
-            patch->address = (u_char *) &equal->offset;
+            patch->address = &equal->offset;
 
             *last = patch;
             last = &patch->next;
@@ -601,7 +601,7 @@ njs_generate_switch_statement(njs_vm_t *vm, njs_parser_t *parser,
             node = branch;
 
         } else {
-            *patch->address += parser->code_end - patch->address;
+            *patch->address += parser->code_end - (u_char *) patch->address;
             next = patch->next;
 
             nxt_mem_cache_free(vm->mem_cache_pool, patch);
@@ -954,7 +954,7 @@ njs_generate_patch_loop_continuation(njs_vm_t *vm, njs_parser_t *parser)
     block = parser->block;
 
     for (patch = block->continuation; patch != NULL; patch = next) {
-        *patch->address += parser->code_end - patch->address;
+        *patch->address += parser->code_end - (u_char *) patch->address;
         next = patch->next;
 
         nxt_mem_cache_free(vm->mem_cache_pool, patch);
@@ -972,7 +972,7 @@ njs_generate_patch_block_exit(njs_vm_t *vm, njs_parser_t *parser)
     parser->block = block->next;
 
     for (patch = block->exit; patch != NULL; patch = next) {
-        *patch->address += parser->code_end - patch->address;
+        *patch->address += parser->code_end - (u_char *) patch->address;
         next = patch->next;
 
         nxt_mem_cache_free(vm->mem_cache_pool, patch);
@@ -1013,7 +1013,7 @@ njs_generate_continue_statement(njs_vm_t *vm, njs_parser_t *parser,
         jump->code.retval = NJS_VMCODE_NO_RETVAL;
         jump->offset = offsetof(njs_vmcode_jump_t, offset);
 
-        patch->address = (u_char *) &jump->offset;
+        patch->address = &jump->offset;
     }
 
     return NXT_OK;
@@ -1046,7 +1046,7 @@ njs_generate_break_statement(njs_vm_t *vm, njs_parser_t *parser,
         jump->code.retval = NJS_VMCODE_NO_RETVAL;
         jump->offset = offsetof(njs_vmcode_jump_t, offset);
 
-        patch->address = (u_char *) &jump->offset;
+        patch->address = &jump->offset;
     }
 
     return NXT_OK;
index 01a0c895a3b95e40ec5bcfddd6f1f8b9bac150ad..74ea7622f27ae430babdb9585ffa2b5e43e20bce 100644 (file)
@@ -234,7 +234,13 @@ struct njs_parser_node_s {
 typedef struct njs_parser_patch_s   njs_parser_patch_t;
 
 struct njs_parser_patch_s {
-    u_char                          *address;
+    /*
+     * The address field points to jump offset field which contains a small
+     * adjustment and the adjustment should be added as (njs_ret_t *) because
+     * pointer to u_char accesses only one byte so this does not work on big
+     * endian platforms.
+     */
+    njs_ret_t                       *address;
     njs_parser_patch_t              *next;
 };