Range check option row index from lua in ScreenOptions:GetOptionRow to fix seg fault.

This commit is contained in:
Kyzentun
2015-01-12 13:08:38 -07:00
parent ce085034f2
commit b2ceb184fa
5 changed files with 19 additions and 1 deletions
+4
View File
@@ -4,6 +4,10 @@ The StepMania 5 Changelog covers all post-sm-ssc changes. For a list of changes
from StepMania 4 alpha 5 to sm-ssc v1.2.5, see Changelog_sm-ssc.txt.
________________________________________________________________________________
2015/01/12
----------
* [ScreenOptions] GetNumRows function added. [kyzentun]
2015/01/09
----------
* [Sprite] SetStateProperties function added. [kyzentun]
+1
View File
@@ -1442,6 +1442,7 @@
<Function name='AllAreOnLastRow'/>
<Function name='FocusedItemEndsScreen'/>
<Function name='GetCurrentRowIndex'/>
<Function name='GetNumRows'/>
<Function name='GetOptionRow'/>
</Class>
<Class base='ScreenOptions' name='ScreenPlayerOptions'>
+3
View File
@@ -4185,6 +4185,9 @@ save yourself some time, copy this for undocumented things:
<Function name='GetCurrentRowIndex' renamed='true' return='int' arguments='PlayerNumber pn'>
Returns the current row that player <code>pn</code> is on. (Was previously <code>GetCurrentRow</code>.)
</Function>
<Function name='GetNumRows' return='int' arguments=''>
Returns the number of rows on the screen.
</Function>
<Function name='GetOptionRow' return='OptionRow' arguments='int iRow'>
Returns the specified OptionRow.
</Function>
+10 -1
View File
@@ -1352,13 +1352,21 @@ public:
static int FocusedItemEndsScreen( T* p, lua_State *L ) { lua_pushboolean( L, p->FocusedItemEndsScreen(Enum::Check<PlayerNumber>(L, 1)) ); return 1; }
static int GetCurrentRowIndex( T* p, lua_State *L ) { lua_pushnumber( L, p->GetCurrentRow(Enum::Check<PlayerNumber>(L, 1)) ); return 1; }
static int GetOptionRow( T* p, lua_State *L ) {
OptionRow* pOptRow = p->GetRow( IArg(1) );
int row_index= IArg(1);
// TODO: Change row indices to be 1-indexed when breaking compatibility
// is allowed. -Kyz
if(row_index < 0 || row_index >= p->GetNumRows())
{
luaL_error(L, "Row index %d is invalid.", row_index);
}
OptionRow* pOptRow = p->GetRow(row_index);
if( pOptRow )
pOptRow->PushSelf(L);
else
lua_pushnil( L );
return 1;
}
DEFINE_METHOD(GetNumRows, GetNumRows());
//static int SetOptionRowFromName( T* p, lua_State *L ) { p->SetOptionRowFromName( SArg(1) ); return 0; }
LunaScreenOptions()
@@ -1367,6 +1375,7 @@ public:
ADD_METHOD( FocusedItemEndsScreen );
ADD_METHOD( GetCurrentRowIndex );
ADD_METHOD( GetOptionRow );
ADD_METHOD( GetNumRows );
//ADD_METHOD( SetOptionRowFromName );
}
};
+1
View File
@@ -98,6 +98,7 @@ protected:
bool AllAreOnLastRow() const;
OptionRow* GetRow( int iRow ) const { return m_pRows[iRow]; }
//void SetOptionRowFromName( const RString& nombre );
int GetNumRows() const { return static_cast<int>(m_pRows.size()); }
protected: // derived classes need access to these
enum Navigation { NAV_THREE_KEY, NAV_THREE_KEY_MENU, NAV_THREE_KEY_ALT, NAV_FIVE_KEY, NAV_TOGGLE_THREE_KEY, NAV_TOGGLE_FIVE_KEY };