Permalink
Browse files

Merge pull request #152 from jinglong/bytecode

fix strict-aliasing warnings in ngx_http_lua_clfactory_bytecode_prepare
  • Loading branch information...
2 parents 2bea026 + f9dc0dc commit e6297a5db0d177d6405bccf976eeac33d2b50244 @agentzh agentzh committed Sep 26, 2012
Showing with 15 additions and 11 deletions.
  1. +15 −11 src/ngx_http_lua_clfactory.c
View
26 src/ngx_http_lua_clfactory.c
@@ -283,8 +283,9 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
{
int x = 1, size_of_int, size_of_size_t, little_endian,
size_of_inst, version, stripped;
- size_t size, bytecode_len;
+ static int num_of_inst = 3, num_of_inter_func = 1;
const char *filename, *emsg, *serr, *bytecode;
+ size_t size, bytecode_len;
ngx_file_info_t fi;
serr = NULL;
@@ -404,12 +405,13 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
goto error;
}
- /* source string length */
- *(size_t *) (lf->begin_code.str + POS_SOURCE_STR_LEN) = 0;
- /* start line */
- *(int *) (lf->begin_code.str + POS_START_LINE) = 0;
- /* last line */
- *(int *) (lf->begin_code.str + POS_LAST_LINE) = 0;
+ /* clear the following fields to zero:
+ * - source string length
+ * - start line
+ * - last line
+ */
+ ngx_memzero(lf->begin_code.str + POS_SOURCE_STR_LEN,
+ sizeof(size_t) + sizeof(int) * 2);
/* number of upvalues */
*(lf->begin_code.str + POS_NUM_OF_UPVS) = 0;
/* number of paramters */
@@ -419,7 +421,8 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
/* max stack size */
*(lf->begin_code.str + POS_MAX_STACK_SIZE) = 2;
/* number of bytecode instructions */
- *(int *) (lf->begin_code.str + POS_NUM_OF_INST) = 3;
+ ngx_memcpy(lf->begin_code.str + POS_NUM_OF_INST, &num_of_inst,
+ sizeof(int));
lf->begin_code_len = POS_BYTECODE;
@@ -448,10 +451,11 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
ngx_memcpy(lf->begin_code.str + POS_BYTECODE, bytecode, bytecode_len);
/* number of consts */
- *(int *) (lf->begin_code.str + POS_BYTECODE + bytecode_len) = 0;
+ ngx_memzero(lf->begin_code.str + POS_BYTECODE + bytecode_len,
+ sizeof(int));
/* number of internal functions */
- *(int *) (lf->begin_code.str + POS_BYTECODE + bytecode_len
- + sizeof(int)) = 1;
+ ngx_memcpy(lf->begin_code.str + POS_BYTECODE + bytecode_len
+ + sizeof(int), &num_of_inter_func, sizeof(int));
lf->begin_code_len += bytecode_len + sizeof(int) + sizeof(int);

0 comments on commit e6297a5

Please sign in to comment.