getSocketAddressList leading spaces handling and tests

This commit is contained in:
Matej Sekoranja
2014-11-17 09:56:40 +01:00
parent b3c030d946
commit 0a82f3c60a
2 changed files with 40 additions and 4 deletions

View File

@@ -146,8 +146,13 @@ InetAddrVector* getSocketAddressList(const std::string & list, int defaultPort,
const InetAddrVector* appendList) {
InetAddrVector* iav = new InetAddrVector();
// parse string
// skip leading spaces
size_t len = list.length();
size_t subStart = 0;
while (subStart < len && isspace(list[subStart]))
subStart++;
// parse string
size_t subEnd;
while((subEnd = list.find(' ', subStart))!=std::string::npos) {
string address = list.substr(subStart, (subEnd-subStart));
@@ -157,7 +162,7 @@ InetAddrVector* getSocketAddressList(const std::string & list, int defaultPort,
subStart = list.find_first_not_of(" \t\r\n\v", subEnd);
}
if(subStart!=std::string::npos&&list.length()>0) {
if(subStart!=std::string::npos && subStart<len) {
osiSockAddr addr;
if (aToIPAddr(list.substr(subStart).c_str(), defaultPort, &addr.ia) == 0)
iav->push_back(addr);