]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
str_list: fix buffer index when start<0
authorSage Weil <sage@newdream.net>
Sun, 12 Sep 2010 03:57:23 +0000 (20:57 -0700)
committerSage Weil <sage@newdream.net>
Sun, 12 Sep 2010 03:57:40 +0000 (20:57 -0700)
find_first_no_of() can return a negative value.

src/common/str_list.cc

index 8b2b5b163018e86980ff51cb80902d2ab98cd10c..0e2cafbf95b257ad03288ebecbcfa0e514731363 100644 (file)
@@ -9,24 +9,19 @@ static bool get_next_token(string s, size_t& pos, string& token)
   int start = s.find_first_not_of(" \t", pos);
   int end;
 
-  if (s[start]== ',') {
+  if (start < 0)
+    return false; 
+
+  if (s[start]== ',')
     end = start + 1;
-  } else {
+  else
     end = s.find_first_of(";,= \t", start+1);
-  }
 
-  if (start < 0) {
-    return false; 
-  }
-
-  if (end < 0) {
-    end=s.size();
-  }
+  if (end < 0)
+    end = s.size();
 
   token = s.substr(start, end - start);
-
   pos = end;
-
   return true;
 }