Fixed potential overflow in C and C++ code, in worst case when int type is int16.

This commit is contained in:
Project Nayuki
2017-04-20 04:08:26 +00:00
parent 3e634c9f26
commit 31634fc05c
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -483,7 +483,7 @@ long qrcodegen::QrCode::getPenaltyScore() const {
}
int total = size * size;
// Find smallest k such that (45-5k)% <= dark/total <= (55+5k)%
for (int k = 0; black*20 < (9-k)*total || black*20 > (11+k)*total; k++)
for (int k = 0; black*20L < (9L-k)*total || black*20L > (11L+k)*total; k++)
result += PENALTY_N4;
return result;
}