From 1598deda7f19995e7427b3298e4cacc682875b32 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Thu, 21 Sep 2006 09:42:08 +0000 Subject: [PATCH] Fix crash if lua_tostring() returns NULL. --- stepmania/src/LuaManager.cpp | 19 +++++++++++++++---- stepmania/src/PercentageDisplay.cpp | 3 +-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index d7cc707515..a239d9d560 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -343,7 +343,9 @@ XNode *LuaManager::GetLuaInformation() const while( lua_next(L, -2) ) { lua_pop( L, 1 ); // pop value - c.m_vMethods.push_back( lua_tostring(L, -1) ); + RString sKey; + if( LuaHelpers::FromStack(sKey, -1, L) ) + c.m_vMethods.push_back( sKey ); } sort( c.m_vMethods.begin(), c.m_vMethods.end() ); } @@ -374,7 +376,11 @@ XNode *LuaManager::GetLuaInformation() const const char *type = lua_tostring( L, -1 ); if( type ) - mSingletons[lua_tostring(L, -6)] = type; + { + RString sKey; + if( LuaHelpers::FromStack(sKey, -6, L) ) + mSingletons[sKey] = type; + } lua_pop( L, 4 ); // pop type, method metatable, method table, and metatable break; } @@ -384,7 +390,11 @@ XNode *LuaManager::GetLuaInformation() const float fNum = float( lua_tonumber(L, -1) ); if( fNum == truncf(fNum) ) - mConstants[lua_tostring(L, -2)] = int( fNum ); + { + RString sKey; + if( LuaHelpers::FromStack(sKey, -2, L) ) + mConstants[sKey] = int( fNum ); + } break; } } @@ -625,7 +635,8 @@ RString GetLuaBindingType( Lua *L, int iArgNo ) int iMetatable = lua_gettop( L ); lua_pushstring( L, "type" ); lua_rawget( L, iMetatable ); - RString sActualType = lua_tostring( L, -1 ); + RString sActualType; + LuaHelpers::FromStack( sActualType, -1, L ); lua_settop( L, iTop ); return sActualType; diff --git a/stepmania/src/PercentageDisplay.cpp b/stepmania/src/PercentageDisplay.cpp index a5e638b467..939f66d071 100644 --- a/stepmania/src/PercentageDisplay.cpp +++ b/stepmania/src/PercentageDisplay.cpp @@ -169,8 +169,7 @@ void PercentageDisplay::Refresh() ASSERT( !lua_isnil(L, -1) ); LuaHelpers::Push( fPercentDancePoints, L ); lua_call( L, 1, 1 ); // 1 args, 1 result - sNumToDisplay = lua_tostring( L, -1 ); - lua_pop( L, 1 ); + LuaHelpers::Pop( sNumToDisplay, L ); LUA->Release(L); // HACK: Use the last frame in the numbers texture as '-'