summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Lozano <ivanlozano@google.com>2017-11-07 13:13:55 -0800
committerIvan Lozano <ivanlozano@google.com>2017-12-20 14:59:19 -0800
commit44d3cacfce3054d395e47dced8c552dba1133b5c (patch)
treee0da3ad87837ecaf2321da26585c86127a3524de
parente3114fdec9e03b8cdc11ef19b5a7091e69ba8374 (diff)
Fix sanitizer errors in bootstat.cpp.
Integer overflow sanitized builds are throwing an error on the while loop decrement in the rfind function. This refactors the loop to prevent decrementing the value on the final iteration. Test: Compiled and device boots without runtime error. Bug: 30969751 Change-Id: Ice4532cce933062b3c14adf2d9749cfdea4ad84c Merged-In: Ice4532cce933062b3c14adf2d9749cfdea4ad84c
-rw-r--r--bootstat/bootstat.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index b19ab781f..23c7d5dfc 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -432,9 +432,11 @@ class pstoreConsole {
if (needle.length() > pos) return std::string::npos;
pos -= needle.length();
// fuzzy match to maximum kBitErrorRate
- do {
+ for (;;) {
if (numError(pos, needle) != std::string::npos) return pos;
- } while (pos-- != 0);
+ if (pos == 0) break;
+ --pos;
+ }
return std::string::npos;
}