added length checks to strings that can otherwise break with Metroworks compilers

This commit is contained in:
mes5k 2008-05-23 22:15:45 +00:00
parent bb477f8d10
commit 20d8d8b531
2 changed files with 5 additions and 3 deletions

View File

@ -461,7 +461,7 @@ inline void CmdLine::parse(std::vector<std::string>& args)
inline bool CmdLine::_emptyCombined(const std::string& s)
{
if ( s[0] != Arg::flagStartChar() )
if ( s.length() > 0 && s[0] != Arg::flagStartChar() )
return false;
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )

View File

@ -139,7 +139,8 @@ inline bool SwitchArg::getValue() { return _value; }
inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
{
// make sure this is actually a combined switch
if ( combinedSwitches[0] != Arg::flagStartString()[0] )
if ( combinedSwitches.length() > 0 &&
combinedSwitches[0] != Arg::flagStartString()[0] )
return false;
// make sure it isn't a long name
@ -154,7 +155,8 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
// ok, we're not specifying a ValueArg, so we know that we have
// a combined switch list.
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
if ( combinedSwitches[i] == _flag[0] &&
if ( _flag.length() > 0 &&
combinedSwitches[i] == _flag[0] &&
_flag[0] != Arg::flagStartString()[0] )
{
// update the combined switches so this one is no longer present