Handle exceptions in int conversions (#2092)

* RageUtil: Add exception-safe wrappers around std::stoi, stol, stoll

* Replace use of std::stoi with exception-safe StringToInt
This commit is contained in:
Gareth Francis
2021-02-15 12:36:51 -08:00
committed by GitHub
parent c7c54bb013
commit aeb5c7598f
25 changed files with 124 additions and 73 deletions
+3 -3
View File
@@ -162,7 +162,7 @@ public:
m_Def.m_bOneChoiceForAllPlayers = false;
ROW_INVALID_IF(lCmds.v[0].m_vsArgs.size() != 1, "Row command has invalid args to number of entries.", false);
const int NumCols = std::stoi( lCmds.v[0].m_vsArgs[0] );
const int NumCols = StringToInt( lCmds.v[0].m_vsArgs[0] );
ROW_INVALID_IF(NumCols < 1, "Not enough entries in list.", false);
for( unsigned i=1; i<lCmds.v.size(); i++ )
{
@@ -174,7 +174,7 @@ public:
else if( sName == "selectone" ) m_Def.m_selectType = SELECT_ONE;
else if( sName == "selectnone" ) m_Def.m_selectType = SELECT_NONE;
else if( sName == "showoneinrow" ) m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
else if( sName == "default" ) m_Def.m_iDefault = std::stoi( cmd.GetArg(1).s ) - 1; // match ENTRY_MODE
else if( sName == "default" ) m_Def.m_iDefault = StringToInt( cmd.GetArg(1).s ) - 1; // match ENTRY_MODE
else if( sName == "reloadrowmessages" )
{
for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ )
@@ -186,7 +186,7 @@ public:
for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ )
{
RString sArg = cmd.m_vsArgs[a];
PlayerNumber pn = (PlayerNumber)(std::stoi(sArg)-1);
PlayerNumber pn = (PlayerNumber)(StringToInt(sArg)-1);
ASSERT( pn >= 0 && pn < NUM_PLAYERS );
m_Def.m_vEnabledForPlayers.insert( pn );
}