@@ -283,8 +283,9 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
283283{
284284 int x = 1 , size_of_int , size_of_size_t , little_endian ,
285285 size_of_inst , version , stripped ;
286- size_t size , bytecode_len ;
286+ static int num_of_inst = 3 , num_of_inter_func = 1 ;
287287 const char * filename , * emsg , * serr , * bytecode ;
288+ size_t size , bytecode_len ;
288289 ngx_file_info_t fi ;
289290
290291 serr = NULL ;
@@ -404,12 +405,13 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
404405 goto error ;
405406 }
406407
407- /* source string length */
408- * (size_t * ) (lf -> begin_code .str + POS_SOURCE_STR_LEN ) = 0 ;
409- /* start line */
410- * (int * ) (lf -> begin_code .str + POS_START_LINE ) = 0 ;
411- /* last line */
412- * (int * ) (lf -> begin_code .str + POS_LAST_LINE ) = 0 ;
408+ /* clear the following fields to zero:
409+ * - source string length
410+ * - start line
411+ * - last line
412+ */
413+ ngx_memzero (lf -> begin_code .str + POS_SOURCE_STR_LEN ,
414+ sizeof (size_t ) + sizeof (int ) * 2 );
413415 /* number of upvalues */
414416 * (lf -> begin_code .str + POS_NUM_OF_UPVS ) = 0 ;
415417 /* number of paramters */
@@ -419,7 +421,8 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
419421 /* max stack size */
420422 * (lf -> begin_code .str + POS_MAX_STACK_SIZE ) = 2 ;
421423 /* number of bytecode instructions */
422- * (int * ) (lf -> begin_code .str + POS_NUM_OF_INST ) = 3 ;
424+ ngx_memcpy (lf -> begin_code .str + POS_NUM_OF_INST , & num_of_inst ,
425+ sizeof (int ));
423426
424427 lf -> begin_code_len = POS_BYTECODE ;
425428
@@ -448,10 +451,11 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
448451 ngx_memcpy (lf -> begin_code .str + POS_BYTECODE , bytecode , bytecode_len );
449452
450453 /* number of consts */
451- * (int * ) (lf -> begin_code .str + POS_BYTECODE + bytecode_len ) = 0 ;
454+ ngx_memzero (lf -> begin_code .str + POS_BYTECODE + bytecode_len ,
455+ sizeof (int ));
452456 /* number of internal functions */
453- * ( int * ) (lf -> begin_code .str + POS_BYTECODE + bytecode_len
454- + sizeof (int )) = 1 ;
457+ ngx_memcpy (lf -> begin_code .str + POS_BYTECODE + bytecode_len
458+ + sizeof (int ), & num_of_inter_func , sizeof ( int )) ;
455459
456460 lf -> begin_code_len += bytecode_len + sizeof (int ) + sizeof (int );
457461
0 commit comments