Message ID | 20171012150217.22379-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | Lua: cleanup stack after notify functions | expand |
Hi Christian, On 12/10/2017 17:02, Christian Storm wrote: > luaL_checkstring() as well as luaL_checknumber() do not pop > from the stack, hence remove notify function arguments by > explicit lua_pop() calls. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > corelib/lua_interface.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index 9698667..39ed01f 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -323,30 +323,37 @@ static int l_notify (lua_State *L) { > if (strlen(msg)) > notify((RECOVERY_STATUS)status, (int)error, INFOLEVEL, msg); > > + lua_pop(L, 3); > return 0; > } > > static int l_trace(lua_State *L) { > + const char *msg = luaL_checkstring (L, 1); > > - const char *msg = luaL_checkstring (L, 1); > if (strlen(msg)) > TRACE("%s", msg); > + > + lua_pop(L, 1); > return 0; > } > > static int l_error(lua_State *L) { > + const char *msg = luaL_checkstring (L, 1); > > - const char *msg = luaL_checkstring (L, 1); > if (strlen(msg)) > ERROR("%s", msg); > + > + lua_pop(L, 1); > return 0; > } > > static int l_info(lua_State *L) { > + const char *msg = luaL_checkstring (L, 1); > > - const char *msg = luaL_checkstring (L, 1); > if (strlen(msg)) > INFO("%s", msg); > + > + lua_pop(L, 1); > return 0; > } > > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
On 12/10/2017 17:02, Christian Storm wrote: > luaL_checkstring() as well as luaL_checknumber() do not pop > from the stack, hence remove notify function arguments by > explicit lua_pop() calls. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > corelib/lua_interface.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index 9698667..39ed01f 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -323,30 +323,37 @@ static int l_notify (lua_State *L) { > if (strlen(msg)) > notify((RECOVERY_STATUS)status, (int)error, INFOLEVEL, msg); > > + lua_pop(L, 3); > return 0; > } > > static int l_trace(lua_State *L) { > + const char *msg = luaL_checkstring (L, 1); > > - const char *msg = luaL_checkstring (L, 1); > if (strlen(msg)) > TRACE("%s", msg); > + > + lua_pop(L, 1); > return 0; > } > > static int l_error(lua_State *L) { > + const char *msg = luaL_checkstring (L, 1); > > - const char *msg = luaL_checkstring (L, 1); > if (strlen(msg)) > ERROR("%s", msg); > + > + lua_pop(L, 1); > return 0; > } > > static int l_info(lua_State *L) { > + const char *msg = luaL_checkstring (L, 1); > > - const char *msg = luaL_checkstring (L, 1); > if (strlen(msg)) > INFO("%s", msg); > + > + lua_pop(L, 1); > return 0; > } > > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 9698667..39ed01f 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -323,30 +323,37 @@ static int l_notify (lua_State *L) { if (strlen(msg)) notify((RECOVERY_STATUS)status, (int)error, INFOLEVEL, msg); + lua_pop(L, 3); return 0; } static int l_trace(lua_State *L) { + const char *msg = luaL_checkstring (L, 1); - const char *msg = luaL_checkstring (L, 1); if (strlen(msg)) TRACE("%s", msg); + + lua_pop(L, 1); return 0; } static int l_error(lua_State *L) { + const char *msg = luaL_checkstring (L, 1); - const char *msg = luaL_checkstring (L, 1); if (strlen(msg)) ERROR("%s", msg); + + lua_pop(L, 1); return 0; } static int l_info(lua_State *L) { + const char *msg = luaL_checkstring (L, 1); - const char *msg = luaL_checkstring (L, 1); if (strlen(msg)) INFO("%s", msg); + + lua_pop(L, 1); return 0; }
luaL_checkstring() as well as luaL_checknumber() do not pop from the stack, hence remove notify function arguments by explicit lua_pop() calls. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- corelib/lua_interface.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)