changeset 146:c20f78d1b4bd draft

fixed runaway memory alloc bug on 64-bit in ParseString found by sirius-m
author s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
date Fri, 05 Mar 2010 01:13:27 +0000
parents 1a5ad24731f4
children 1bf4f0e9e04c
files util.cpp
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/util.cpp
+++ b/util.cpp
@@ -282,15 +282,21 @@
 
 void ParseString(const string& str, char c, vector<string>& v)
 {
-    unsigned int i1 = 0;
-    unsigned int i2;
-    do
+    if (str.empty())
+        return;
+    string::size_type i1 = 0;
+    string::size_type i2;
+    loop
     {
         i2 = str.find(c, i1);
+        if (i2 == str.npos)
+        {
+            v.push_back(str.substr(i1));
+            return;
+        }
         v.push_back(str.substr(i1, i2-i1));
         i1 = i2+1;
     }
-    while (i2 != str.npos);
 }