lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


More one suggestion to Lua code:

at lua_newstate function, the loop for initializing a fixed array,
can be securely changed by memset.

diff --git a/lstate.c b/lstate.c
index 42274292..153b000b 100644
--- a/lstate.c
+++ b/lstate.c
@@ -392,7 +392,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
   g->gcstepsize = LUAI_GCSTEPSIZE;
   setgcparam(g->genmajormul, LUAI_GENMAJORMUL);
   g->genminormul = LUAI_GENMINORMUL;
-  for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
+  memset(g->mt, 0, sizeof(struct Table *) * (size_t) LUA_NUMTAGS);  
   if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
     /* memory allocation error: free partial state */

Ranier Vilela

Attachment: avoid_loop_for_init_fixed_array.patch
Description: Binary data