From 20d8d8b531c3fcc3d5b239815423f74cd996c566 Mon Sep 17 00:00:00 2001 From: mes5k Date: Fri, 23 May 2008 22:15:45 +0000 Subject: [PATCH] added length checks to strings that can otherwise break with Metroworks compilers --- include/tclap/CmdLine.h | 2 +- include/tclap/SwitchArg.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/tclap/CmdLine.h b/include/tclap/CmdLine.h index b736346..a3e6ad3 100644 --- a/include/tclap/CmdLine.h +++ b/include/tclap/CmdLine.h @@ -461,7 +461,7 @@ inline void CmdLine::parse(std::vector& 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(i) < s.length(); i++ ) diff --git a/include/tclap/SwitchArg.h b/include/tclap/SwitchArg.h index 878ed43..e2c541c 100644 --- a/include/tclap/SwitchArg.h +++ b/include/tclap/SwitchArg.h @@ -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