Enable multiple benign overflow conditions.
In VelocityTracker.cpp, there are multiple loops in which loop
termination occurs when the value becomes zero. These termination
conditions are all written value-- > 0, which, since value is
unsigned, result in an integer overflow condition when value is 0.
These loop were refactored to eliminate these conditions.
Bug: 24171356
Change-Id: Ie44940cfef8a122ee1aff59c021274ba39a368bf
diff --git a/libs/input/VelocityTracker.cpp b/libs/input/VelocityTracker.cpp
index 6c70c3c..7f6b157 100644
--- a/libs/input/VelocityTracker.cpp
+++ b/libs/input/VelocityTracker.cpp
@@ -46,7 +46,8 @@
static float vectorDot(const float* a, const float* b, uint32_t m) {
float r = 0;
- while (m--) {
+ while (m) {
+ m--;
r += *(a++) * *(b++);
}
return r;
@@ -54,7 +55,8 @@
static float vectorNorm(const float* a, uint32_t m) {
float r = 0;
- while (m--) {
+ while (m) {
+ m--;
float t = *(a++);
r += t * t;
}
@@ -511,7 +513,8 @@
for (uint32_t h = 0; h < m; h++) {
wy[h] = y[h] * w[h];
}
- for (uint32_t i = n; i-- != 0; ) {
+ for (uint32_t i = n; i != 0; ) {
+ i--;
outB[i] = vectorDot(&q[i][0], wy, m);
for (uint32_t j = n - 1; j > i; j--) {
outB[i] -= r[i][j] * outB[j];