If was pass an empty string (e.g., with something like
get_str_map("M= T= P=")) we end up with a (size_t)-1 for end.
Fixes: http://tracker.ceph.com/issues/38329
Signed-off-by: Sage Weil <sage@redhat.com>
return 0;
}
string trim(const string& str) {
+ if (str.empty()) {
+ return str;
+ }
size_t start = 0;
size_t end = str.size() - 1;
while (start <= end && isspace(str[start]) != 0) {
}
}
+TEST(str_map, empty_values) {
+ {
+ map<string,string> str_map;
+ ASSERT_EQ(0, get_str_map("M= P= L=",
+ &str_map));
+ ASSERT_EQ(3u, str_map.size());
+ ASSERT_EQ("", str_map["M"]);
+ ASSERT_EQ("", str_map["P"]);
+ ASSERT_EQ("", str_map["L"]);
+ }
+}
+
/*
* Local Variables:
* compile-command: "cd ../.. ; make -j4 &&