From ceb51372d3ac7c9dd664ad3bd0766c662d156288 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 17 Apr 2017 16:41:20 +0000 Subject: [PATCH] Updated C++ QrCode private methods to replace some int variables with long to prevent overflow. --- cpp/QrCode.cpp | 8 ++++---- cpp/QrCode.hpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index b732ecb..8357791 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -393,11 +393,11 @@ void qrcodegen::QrCode::applyMask(int mask) { int qrcodegen::QrCode::handleConstructorMasking(int mask) { if (mask == -1) { // Automatically choose best mask - int32_t minPenalty = INT32_MAX; + long minPenalty = LONG_MAX; for (int i = 0; i < 8; i++) { drawFormatBits(i); applyMask(i); - int penalty = getPenaltyScore(); + long penalty = getPenaltyScore(); if (penalty < minPenalty) { mask = i; minPenalty = penalty; @@ -413,8 +413,8 @@ int qrcodegen::QrCode::handleConstructorMasking(int mask) { } -int qrcodegen::QrCode::getPenaltyScore() const { - int result = 0; +long qrcodegen::QrCode::getPenaltyScore() const { + long result = 0; // Adjacent modules in row having same color for (int y = 0; y < size; y++) { diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 325092a..e9a58b7 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -211,7 +211,7 @@ class QrCode final { // Calculates and returns the penalty score based on state of this QR Code's current modules. // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score. - private: int getPenaltyScore() const; + private: long getPenaltyScore() const;