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

pull/65/head
Project Nayuki 6 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"); throw std::logic_error("Assertion error");
// Add terminator and pad up to a byte if applicable // 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) if (bb.size() > dataCapacityBits)
throw std::logic_error("Assertion error"); throw std::logic_error("Assertion error");
bb.appendBits(0, std::min(4, static_cast<int>(dataCapacityBits - bb.size()))); bb.appendBits(0, std::min(4, static_cast<int>(dataCapacityBits - bb.size())));
@ -235,7 +235,7 @@ void QrCode::drawFunctionPatterns() {
// Draw numerous alignment patterns // Draw numerous alignment patterns
const vector<int> alignPatPos = getAlignmentPatternPositions(); 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 i = 0; i < numAlign; i++) {
for (int j = 0; j < numAlign; j++) { for (int j = 0; j < numAlign; j++) {
// Don't draw on the three finder corners // 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); const vector<uint8_t> rsDiv = reedSolomonComputeDivisor(blockEccLen);
for (int i = 0, k = 0; i < numBlocks; i++) { 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))); 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); const vector<uint8_t> ecc = reedSolomonComputeRemainder(dat, rsDiv);
if (i < numShortBlocks) if (i < numShortBlocks)
dat.push_back(0); dat.push_back(0);

@ -26,6 +26,7 @@
* Software. * Software.
*/ */
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -83,7 +84,7 @@ int main() {
try { // Try to make QR Code symbol try { // Try to make QR Code symbol
const QrCode qr = QrCode::encodeSegments(segs, 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 // Print grid of modules
std::cout << qr.getVersion() << std::endl; std::cout << qr.getVersion() << std::endl;
for (int y = 0; y < qr.getSize(); y++) { for (int y = 0; y < qr.getSize(); y++) {

Loading…
Cancel
Save