From ee29f5aa6a653afe4d8bdfed890c3883c52b261a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Sun, 27 Dec 2015 15:23:57 +0300 Subject: [PATCH] The "break" and "continue" statements did not work on big endian platforms. --- njs/njs_generator.c | 12 ++++++------ njs/njs_parser.h | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 120ecd99..f40e493f 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -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; diff --git a/njs/njs_parser.h b/njs/njs_parser.h index 01a0c895..74ea7622 100644 --- a/njs/njs_parser.h +++ b/njs/njs_parser.h @@ -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; }; -- 2.47.3