Fix search for values in blkId output
Bug: 122497152
Test: atest tests/Utils_test.cpp
Test: adb shell sm partition disk:7,32 private ; adb logcat -d
Change-Id: Ic7d32bdbc0c55ce1d21f7f9e74c6a6fb3dcf332a
diff --git a/Utils.cpp b/Utils.cpp
index f00d168..a8273d7 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -202,12 +202,15 @@
bool FindValue(const std::string& raw, const std::string& key, std::string* value) {
auto qual = key + "=\"";
- auto start = raw.find(qual);
- if (start > 0 && raw[start - 1] != ' ') {
- start = raw.find(qual, start + 1);
+ size_t start = 0;
+ while (true) {
+ start = raw.find(qual, start);
+ if (start == std::string::npos) return false;
+ if (start == 0 || raw[start - 1] == ' ') {
+ break;
+ }
+ start += 1;
}
-
- if (start == std::string::npos) return false;
start += qual.length();
auto end = raw.find("\"", start);