In C++ version, added some more explicit casts for integer signedness and width.

pull/65/head
Project Nayuki 5 years ago
parent 1fb40bc113
commit 419b5ae2d7

@ -104,7 +104,7 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, Ecc ecl,
throw std::logic_error("Assertion error");
// Add terminator and pad up to a byte if applicable
size_t dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
size_t dataCapacityBits = static_cast<size_t>(getNumDataCodewords(version, ecl)) * 8;
if (bb.size() > dataCapacityBits)
throw std::logic_error("Assertion error");
bb.appendBits(0, std::min(4, static_cast<int>(dataCapacityBits - bb.size())));
@ -235,7 +235,7 @@ void QrCode::drawFunctionPatterns() {
// Draw numerous alignment patterns
const vector<int> alignPatPos = getAlignmentPatternPositions();
int numAlign = alignPatPos.size();
int numAlign = static_cast<int>(alignPatPos.size());
for (int i = 0; i < numAlign; i++) {
for (int j = 0; j < numAlign; j++) {
// Don't draw on the three finder corners
@ -348,7 +348,7 @@ vector<uint8_t> QrCode::addEccAndInterleave(const vector<uint8_t> &data) const {
const vector<uint8_t> rsDiv = reedSolomonComputeDivisor(blockEccLen);
for (int i = 0, k = 0; i < numBlocks; i++) {
vector<uint8_t> dat(data.cbegin() + k, data.cbegin() + (k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1)));
k += dat.size();
k += static_cast<int>(dat.size());
const vector<uint8_t> ecc = reedSolomonComputeRemainder(dat, rsDiv);
if (i < numShortBlocks)
dat.push_back(0);

@ -26,6 +26,7 @@
* Software.
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
@ -83,7 +84,7 @@ int main() {
try { // Try to make QR Code symbol
const QrCode qr = QrCode::encodeSegments(segs,
ECC_LEVELS.at(errCorLvl), minVersion, maxVersion, mask, boostEcl == 1);
ECC_LEVELS.at(static_cast<std::size_t>(errCorLvl)), minVersion, maxVersion, mask, boostEcl == 1);
// Print grid of modules
std::cout << qr.getVersion() << std::endl;
for (int y = 0; y < qr.getSize(); y++) {

Loading…
Cancel
Save