X-Git-Url: http://git.home-dn.net/?p=manu%2Fsuphp.git;a=blobdiff_plain;f=src%2FCommandLine.cpp;h=602d7737530262cd8bf8c2f60af277739d615254;hp=b718dc4fd4770eba8ae84ad94d55067d2b093408;hb=849f4a7977b5780eacae8fad7a078d05f4a615ee;hpb=873afb00229b8e205345b6895eaad6602d5e10f4 diff --git a/src/CommandLine.cpp b/src/CommandLine.cpp index b718dc4..602d773 100644 --- a/src/CommandLine.cpp +++ b/src/CommandLine.cpp @@ -37,20 +37,23 @@ int suPHP::CommandLine::count() const { std::string suPHP::CommandLine::getArgument(int pos) const throw (OutOfRangeException) { + if (pos >= this->arguments.size() || pos < 0) { + throw OutOfRangeException("Index out of range", __FILE__, __LINE__); + } try { - return this->arguments.at(pos); + return this->arguments[pos]; } catch (std::out_of_range& e) { - throw OutOfRangeException("Index out of range", __FILE__, __LINE__); + throw OutOfRangeException("Index out of range", __FILE__, __LINE__); } } void suPHP::CommandLine::setArgument(int pos, std::string arg) { if (pos >= this->arguments.size()) { - for (int i=0; i<(this->arguments.size() - pos); i++) { - this->arguments.push_back(std::string("")); - } + for (int i=0; i<(this->arguments.size() - pos); i++) { + this->arguments.push_back(std::string("")); + } } - this->arguments.at(pos) = arg; + this->arguments[pos] = arg; } void suPHP::CommandLine::putArgument(std::string arg) { @@ -59,10 +62,13 @@ void suPHP::CommandLine::putArgument(std::string arg) { std::string& suPHP::CommandLine::operator[](int index) throw (OutOfRangeException) { + if (index >= this->arguments.size() || index < 0) { + throw OutOfRangeException("Index out of range", __FILE__, __LINE__); + } try { - return this->arguments.at(index); + return this->arguments[index]; } catch (std::out_of_range& ex) { - throw OutOfRangeException("Index out of range", __FILE__, __LINE__); + throw OutOfRangeException("Index out of range", __FILE__, __LINE__); } }