fixed runaway memory alloc bug on 64-bit in ParseString found by sirius-m

This commit is contained in:
s_nakamoto 2010-03-05 01:13:27 +00:00
parent 9a33582204
commit 91e615bfec
1 changed files with 10 additions and 4 deletions

View File

@ -282,15 +282,21 @@ bool error(const char* format, ...)
void ParseString(const string& str, char c, vector<string>& v) void ParseString(const string& str, char c, vector<string>& v)
{ {
unsigned int i1 = 0; if (str.empty())
unsigned int i2; return;
do string::size_type i1 = 0;
string::size_type i2;
loop
{ {
i2 = str.find(c, i1); i2 = str.find(c, i1);
if (i2 == str.npos)
{
v.push_back(str.substr(i1));
return;
}
v.push_back(str.substr(i1, i2-i1)); v.push_back(str.substr(i1, i2-i1));
i1 = i2+1; i1 = i2+1;
} }
while (i2 != str.npos);
} }