From eb8ac6e2a0eb84f3849d5bd50fd3bd2adb903521 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 12 Jun 2008 11:37:27 -0300 Subject: 'luaL_testudata' does not leave garbage on the stack in case of failure --- lauxlib.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lauxlib.c b/lauxlib.c index f5e1a764..8326f384 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.175 2008/01/03 17:07:59 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.176 2008/01/17 16:24:30 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -165,13 +165,13 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { if (p != NULL) { /* value is a userdata? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ - lua_pop(L, 2); /* remove both metatables */ - return p; - } + if (!lua_rawequal(L, -1, -2)) /* not the same? */ + p = NULL; /* value is a userdata with wrong metatable */ + lua_pop(L, 2); /* remove both metatables */ + return p; } } - return NULL; /* value is not a userdata of the proper type */ + return NULL; /* value is not a userdata with a metatable */ } -- cgit v1.2.3-55-g6feb