adb: make ParseUint reject garbage at the end by default.
Test: adb_test on host
Change-Id: Ie63d89bd08f0b296a3d54ff66aae85fe52d8cd0f
diff --git a/adb/adb_utils.h b/adb/adb_utils.h
index a85ca8c..8b0dcee 100644
--- a/adb/adb_utils.h
+++ b/adb/adb_utils.h
@@ -110,7 +110,7 @@
// Base-10 stroll on a string_view.
template <typename T>
-inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining) {
+inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining = nullptr) {
if (str.empty() || !isdigit(str[0])) {
return false;
}
@@ -135,6 +135,9 @@
*result = value;
if (remaining) {
*remaining = str.substr(it - str.begin());
+ } else {
+ return it == str.end();
}
+
return true;
}