From c3479c004321f53735471c8717eb19564a4f9722 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 14:59:37 +0000 Subject: [PATCH 01/12] In C++ version, added explicit casts from int/long to uint32_t for first argument of calls to BitBuffer.appendBits(). --- cpp/QrCode.cpp | 4 ++-- cpp/QrCodeGeneratorDemo.cpp | 2 +- cpp/QrSegment.cpp | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 4630752..faff7ae 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -96,8 +96,8 @@ QrCode QrCode::encodeSegments(const vector &segs, Ecc ecl, // Concatenate all segments to create the data bit string BitBuffer bb; for (const QrSegment &seg : segs) { - bb.appendBits(seg.getMode().getModeBits(), 4); - bb.appendBits(seg.getNumChars(), seg.getMode().numCharCountBits(version)); + bb.appendBits(static_cast(seg.getMode().getModeBits()), 4); + bb.appendBits(static_cast(seg.getNumChars()), seg.getMode().numCharCountBits(version)); bb.insert(bb.end(), seg.getData().begin(), seg.getData().end()); } if (bb.size() != static_cast(dataUsedBits)) diff --git a/cpp/QrCodeGeneratorDemo.cpp b/cpp/QrCodeGeneratorDemo.cpp index 1286433..d8ee821 100644 --- a/cpp/QrCodeGeneratorDemo.cpp +++ b/cpp/QrCodeGeneratorDemo.cpp @@ -153,7 +153,7 @@ static void doSegmentDemo() { }; qrcodegen::BitBuffer bb; for (int c : kanjiChars) - bb.appendBits(c, 13); + bb.appendBits(static_cast(c), 13); const QrCode qr5 = QrCode::encodeSegments( {QrSegment(QrSegment::Mode::KANJI, kanjiChars.size(), bb)}, QrCode::Ecc::LOW); diff --git a/cpp/QrSegment.cpp b/cpp/QrSegment.cpp index 64d77f7..a12f273 100644 --- a/cpp/QrSegment.cpp +++ b/cpp/QrSegment.cpp @@ -81,13 +81,13 @@ QrSegment QrSegment::makeNumeric(const char *digits) { accumData = accumData * 10 + (c - '0'); accumCount++; if (accumCount == 3) { - bb.appendBits(accumData, 10); + bb.appendBits(static_cast(accumData), 10); accumData = 0; accumCount = 0; } } if (accumCount > 0) // 1 or 2 digits remaining - bb.appendBits(accumData, accumCount * 3 + 1); + bb.appendBits(static_cast(accumData), accumCount * 3 + 1); return QrSegment(Mode::NUMERIC, charCount, std::move(bb)); } @@ -104,13 +104,13 @@ QrSegment QrSegment::makeAlphanumeric(const char *text) { accumData = accumData * 45 + (temp - ALPHANUMERIC_CHARSET); accumCount++; if (accumCount == 2) { - bb.appendBits(accumData, 11); + bb.appendBits(static_cast(accumData), 11); accumData = 0; accumCount = 0; } } if (accumCount > 0) // 1 character remaining - bb.appendBits(accumData, 6); + bb.appendBits(static_cast(accumData), 6); return QrSegment(Mode::ALPHANUMERIC, charCount, std::move(bb)); } @@ -138,13 +138,13 @@ QrSegment QrSegment::makeEci(long assignVal) { if (assignVal < 0) throw std::domain_error("ECI assignment value out of range"); else if (assignVal < (1 << 7)) - bb.appendBits(assignVal, 8); + bb.appendBits(static_cast(assignVal), 8); else if (assignVal < (1 << 14)) { bb.appendBits(2, 2); - bb.appendBits(assignVal, 14); + bb.appendBits(static_cast(assignVal), 14); } else if (assignVal < 1000000L) { bb.appendBits(6, 3); - bb.appendBits(assignVal, 21); + bb.appendBits(static_cast(assignVal), 21); } else throw std::domain_error("ECI assignment value out of range"); return QrSegment(Mode::ECI, 0, std::move(bb)); From 1fb40bc11354bf216fc031809af560778a44dc0e Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 15:00:00 +0000 Subject: [PATCH 02/12] In C++ version, added explicit integer casts for second argument of calls to BitBuffer.appendBits(). --- cpp/QrCode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index faff7ae..c849f44 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -107,8 +107,8 @@ QrCode QrCode::encodeSegments(const vector &segs, Ecc ecl, size_t dataCapacityBits = getNumDataCodewords(version, ecl) * 8; if (bb.size() > dataCapacityBits) throw std::logic_error("Assertion error"); - bb.appendBits(0, std::min(4, dataCapacityBits - bb.size())); - bb.appendBits(0, (8 - bb.size() % 8) % 8); + bb.appendBits(0, std::min(4, static_cast(dataCapacityBits - bb.size()))); + bb.appendBits(0, (8 - static_cast(bb.size() % 8)) % 8); if (bb.size() % 8 != 0) throw std::logic_error("Assertion error"); From 419b5ae2d79665dcf198aed2cb5cb11a747af180 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 15:02:22 +0000 Subject: [PATCH 03/12] In C++ version, added some more explicit casts for integer signedness and width. --- cpp/QrCode.cpp | 6 +++--- cpp/QrCodeGeneratorWorker.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index c849f44..9eef0e4 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -104,7 +104,7 @@ QrCode QrCode::encodeSegments(const vector &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(getNumDataCodewords(version, ecl)) * 8; if (bb.size() > dataCapacityBits) throw std::logic_error("Assertion error"); bb.appendBits(0, std::min(4, static_cast(dataCapacityBits - bb.size()))); @@ -235,7 +235,7 @@ void QrCode::drawFunctionPatterns() { // Draw numerous alignment patterns const vector alignPatPos = getAlignmentPatternPositions(); - int numAlign = alignPatPos.size(); + int numAlign = static_cast(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 QrCode::addEccAndInterleave(const vector &data) const { const vector rsDiv = reedSolomonComputeDivisor(blockEccLen); for (int i = 0, k = 0; i < numBlocks; i++) { vector dat(data.cbegin() + k, data.cbegin() + (k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1))); - k += dat.size(); + k += static_cast(dat.size()); const vector ecc = reedSolomonComputeRemainder(dat, rsDiv); if (i < numShortBlocks) dat.push_back(0); diff --git a/cpp/QrCodeGeneratorWorker.cpp b/cpp/QrCodeGeneratorWorker.cpp index 2295593..073107f 100644 --- a/cpp/QrCodeGeneratorWorker.cpp +++ b/cpp/QrCodeGeneratorWorker.cpp @@ -26,6 +26,7 @@ * Software. */ +#include #include #include #include @@ -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(errCorLvl)), minVersion, maxVersion, mask, boostEcl == 1); // Print grid of modules std::cout << qr.getVersion() << std::endl; for (int y = 0; y < qr.getSize(); y++) { From a8a91e0d38e4af6f2a6d666a14bdf8d218726221 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 15:18:18 +0000 Subject: [PATCH 04/12] In C++ version, fixed all remaining implicit integer signedness conversions with the help of GCC's "-Wsign-conversion" and "-Wconversion". --- cpp/QrCode.cpp | 32 ++++++++++++++++++-------------- cpp/QrCodeGeneratorDemo.cpp | 2 +- cpp/QrSegment.cpp | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 9eef0e4..e6a287d 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -135,8 +135,9 @@ QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) if (mask < -1 || mask > 7) throw std::domain_error("Mask value out of range"); size = ver * 4 + 17; - modules = vector >(size, vector(size)); // Initially all white - isFunction = vector >(size, vector(size)); + size_t sz = static_cast(size); + modules = vector >(sz, vector(sz)); // Initially all white + isFunction = vector >(sz, vector(sz)); // Compute ECC, draw modules drawFunctionPatterns(); @@ -235,9 +236,9 @@ void QrCode::drawFunctionPatterns() { // Draw numerous alignment patterns const vector alignPatPos = getAlignmentPatternPositions(); - int numAlign = static_cast(alignPatPos.size()); - for (int i = 0; i < numAlign; i++) { - for (int j = 0; j < numAlign; j++) { + size_t numAlign = alignPatPos.size(); + for (size_t i = 0; i < numAlign; i++) { + for (size_t j = 0; j < numAlign; j++) { // Don't draw on the three finder corners if (!((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0))) drawAlignmentPattern(alignPatPos.at(i), alignPatPos.at(j)); @@ -322,13 +323,15 @@ void QrCode::drawAlignmentPattern(int x, int y) { void QrCode::setFunctionModule(int x, int y, bool isBlack) { - modules.at(y).at(x) = isBlack; - isFunction.at(y).at(x) = true; + size_t ux = static_cast(x); + size_t uy = static_cast(y); + modules.at(uy).at(ux) = isBlack; + isFunction.at(uy).at(ux) = true; } bool QrCode::module(int x, int y) const { - return modules.at(y).at(x); + return modules.at(static_cast(y)).at(static_cast(x)); } @@ -382,9 +385,9 @@ void QrCode::drawCodewords(const vector &data) { right = 5; for (int vert = 0; vert < size; vert++) { // Vertical counter for (int j = 0; j < 2; j++) { - int x = right - j; // Actual x coordinate + size_t x = static_cast(right - j); // Actual x coordinate bool upward = ((right + 1) & 2) == 0; - int y = upward ? size - 1 - vert : vert; // Actual y coordinate + size_t y = static_cast(upward ? size - 1 - vert : vert); // Actual y coordinate if (!isFunction.at(y).at(x) && i < data.size() * 8) { modules.at(y).at(x) = getBit(data.at(i >> 3), 7 - static_cast(i & 7)); i++; @@ -402,8 +405,9 @@ void QrCode::drawCodewords(const vector &data) { void QrCode::applyMask(int mask) { if (mask < 0 || mask > 7) throw std::domain_error("Mask value out of range"); - for (int y = 0; y < size; y++) { - for (int x = 0; x < size; x++) { + size_t sz = static_cast(size); + for (size_t y = 0; y < sz; y++) { + for (size_t x = 0; x < sz; x++) { bool invert; switch (mask) { case 0: invert = (x + y) % 2 == 0; break; @@ -543,8 +547,8 @@ vector QrCode::reedSolomonComputeDivisor(int degree) { throw std::domain_error("Degree out of range"); // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1. // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array {255, 8, 93}. - vector result(degree); - result.at(degree - 1) = 1; // Start off with the monomial x^0 + vector result(static_cast(degree)); + result.at(result.size() - 1) = 1; // Start off with the monomial x^0 // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), // and drop the highest monomial term which is always 1x^degree. diff --git a/cpp/QrCodeGeneratorDemo.cpp b/cpp/QrCodeGeneratorDemo.cpp index d8ee821..8284cfa 100644 --- a/cpp/QrCodeGeneratorDemo.cpp +++ b/cpp/QrCodeGeneratorDemo.cpp @@ -155,7 +155,7 @@ static void doSegmentDemo() { for (int c : kanjiChars) bb.appendBits(static_cast(c), 13); const QrCode qr5 = QrCode::encodeSegments( - {QrSegment(QrSegment::Mode::KANJI, kanjiChars.size(), bb)}, + {QrSegment(QrSegment::Mode::KANJI, static_cast(kanjiChars.size()), bb)}, QrCode::Ecc::LOW); printQr(qr5); } diff --git a/cpp/QrSegment.cpp b/cpp/QrSegment.cpp index a12f273..45ea843 100644 --- a/cpp/QrSegment.cpp +++ b/cpp/QrSegment.cpp @@ -101,7 +101,7 @@ QrSegment QrSegment::makeAlphanumeric(const char *text) { const char *temp = std::strchr(ALPHANUMERIC_CHARSET, *text); if (temp == nullptr) throw std::domain_error("String contains unencodable characters in alphanumeric mode"); - accumData = accumData * 45 + (temp - ALPHANUMERIC_CHARSET); + accumData = accumData * 45 + static_cast(temp - ALPHANUMERIC_CHARSET); accumCount++; if (accumCount == 2) { bb.appendBits(static_cast(accumData), 11); From 9312480978d70003a2051e766ee2208cd00eac69 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 16:31:22 +0000 Subject: [PATCH 05/12] In C version, added many explicit integer type casts for signedness, with the help of GCC's "-Wsign-conversion" and "-Wconversion". --- c/qrcodegen-demo.c | 2 +- c/qrcodegen-test.c | 34 +++++++++++++++++----------------- c/qrcodegen-worker.c | 10 +++++----- c/qrcodegen.c | 34 ++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/c/qrcodegen-demo.c b/c/qrcodegen-demo.c index ef44108..872f48b 100644 --- a/c/qrcodegen-demo.c +++ b/c/qrcodegen-demo.c @@ -224,7 +224,7 @@ static void doSegmentDemo(void) { uint8_t *segBuf = calloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_KANJI, len), sizeof(uint8_t)); struct qrcodegen_Segment seg; seg.mode = qrcodegen_Mode_KANJI; - seg.numChars = len; + seg.numChars = (int)len; seg.bitLength = 0; for (size_t i = 0; i < len; i++) { for (int j = 12; j >= 0; j--, seg.bitLength++) diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index db48b11..30bb318 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -114,13 +114,13 @@ static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, e int shortBlockLen = rawCodewords / numBlocks; // Split data into blocks and append ECC to each block - uint8_t **blocks = malloc(numBlocks * sizeof(uint8_t*)); - uint8_t *generator = malloc(blockEccLen * sizeof(uint8_t)); + uint8_t **blocks = malloc((size_t)numBlocks * sizeof(uint8_t*)); + uint8_t *generator = malloc((size_t)blockEccLen * sizeof(uint8_t)); reedSolomonComputeDivisor(blockEccLen, generator); for (int i = 0, k = 0; i < numBlocks; i++) { - uint8_t *block = malloc((shortBlockLen + 1) * sizeof(uint8_t)); + uint8_t *block = malloc((size_t)(shortBlockLen + 1) * sizeof(uint8_t)); int datLen = shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1); - memcpy(block, &data[k], datLen * sizeof(uint8_t)); + memcpy(block, &data[k], (size_t)datLen * sizeof(uint8_t)); reedSolomonComputeRemainder(&data[k], datLen, generator, blockEccLen, &block[shortBlockLen + 1 - blockEccLen]); k += datLen; blocks[i] = block; @@ -128,7 +128,7 @@ static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, e free(generator); // Interleave (not concatenate) the bytes from every block into a single sequence - uint8_t *result = malloc(rawCodewords * sizeof(uint8_t)); + uint8_t *result = malloc((size_t)rawCodewords * sizeof(uint8_t)); for (int i = 0, k = 0; i < shortBlockLen + 1; i++) { for (int j = 0; j < numBlocks; j++) { // Skip the padding byte in short blocks @@ -149,18 +149,18 @@ static void testAddEccAndInterleave(void) { for (int version = 1; version <= 40; version++) { for (int ecl = 0; ecl < 4; ecl++) { int dataLen = getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl); - uint8_t *pureData = malloc(dataLen * sizeof(uint8_t)); + uint8_t *pureData = malloc((size_t)dataLen * sizeof(uint8_t)); for (int i = 0; i < dataLen; i++) - pureData[i] = rand() % 256; + pureData[i] = (uint8_t)(rand() % 256); uint8_t *expectOutput = addEccAndInterleaveReference(pureData, version, (enum qrcodegen_Ecc)ecl); int dataAndEccLen = getNumRawDataModules(version) / 8; - uint8_t *paddedData = malloc(dataAndEccLen * sizeof(uint8_t)); - memcpy(paddedData, pureData, dataLen * sizeof(uint8_t)); - uint8_t *actualOutput = malloc(dataAndEccLen * sizeof(uint8_t)); + uint8_t *paddedData = malloc((size_t)dataAndEccLen * sizeof(uint8_t)); + memcpy(paddedData, pureData, (size_t)dataLen * sizeof(uint8_t)); + uint8_t *actualOutput = malloc((size_t)dataAndEccLen * sizeof(uint8_t)); addEccAndInterleave(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput); - assert(memcmp(actualOutput, expectOutput, dataAndEccLen * sizeof(uint8_t)) == 0); + assert(memcmp(actualOutput, expectOutput, (size_t)dataAndEccLen * sizeof(uint8_t)) == 0); free(pureData); free(expectOutput); free(paddedData); @@ -362,7 +362,7 @@ static void testReedSolomonMultiply(void) { static void testInitializeFunctionModulesEtc(void) { for (int ver = 1; ver <= 40; ver++) { - uint8_t *qrcode = malloc(qrcodegen_BUFFER_LEN_FOR_VERSION(ver) * sizeof(uint8_t)); + uint8_t *qrcode = malloc((size_t)qrcodegen_BUFFER_LEN_FOR_VERSION(ver) * sizeof(uint8_t)); assert(qrcode != NULL); initializeFunctionModules(ver, qrcode); @@ -718,7 +718,7 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_NUMERIC, cases[i][0]) == cases[i][1]); + assert(calcSegmentBitLength(qrcodegen_Mode_NUMERIC, (size_t)cases[i][0]) == cases[i][1]); numTestCases++; } } @@ -748,7 +748,7 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_ALPHANUMERIC, cases[i][0]) == cases[i][1]); + assert(calcSegmentBitLength(qrcodegen_Mode_ALPHANUMERIC, (size_t)cases[i][0]) == cases[i][1]); numTestCases++; } } @@ -777,7 +777,7 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_BYTE, cases[i][0]) == cases[i][1]); + assert(calcSegmentBitLength(qrcodegen_Mode_BYTE, (size_t)cases[i][0]) == cases[i][1]); numTestCases++; } } @@ -805,7 +805,7 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_KANJI, cases[i][0]) == cases[i][1]); + assert(calcSegmentBitLength(qrcodegen_Mode_KANJI, (size_t)cases[i][0]) == cases[i][1]); numTestCases++; } } @@ -1049,7 +1049,7 @@ static void testGetTotalBits(void) { /*---- Main runner ----*/ int main(void) { - srand(time(NULL)); + srand((unsigned int)time(NULL)); testAppendBitsToBuffer(); testAddEccAndInterleave(); testGetNumDataCodewords(); diff --git a/c/qrcodegen-worker.c b/c/qrcodegen-worker.c index b57d30e..b41a037 100644 --- a/c/qrcodegen-worker.c +++ b/c/qrcodegen-worker.c @@ -47,7 +47,7 @@ int main(void) { // Read data bytes bool isAscii = true; - uint8_t *data = malloc(length * sizeof(uint8_t)); + uint8_t *data = malloc((size_t)length * sizeof(uint8_t)); if (data == NULL) { perror("malloc"); return EXIT_FAILURE; @@ -67,8 +67,8 @@ int main(void) { // Allocate memory for QR Code int bufferLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); - uint8_t *qrcode = malloc(bufferLen * sizeof(uint8_t)); - uint8_t *tempBuffer = malloc(bufferLen * sizeof(uint8_t)); + uint8_t *qrcode = malloc((size_t)bufferLen * sizeof(uint8_t)); + uint8_t *tempBuffer = malloc((size_t)bufferLen * sizeof(uint8_t)); if (qrcode == NULL || tempBuffer == NULL) { perror("malloc"); return EXIT_FAILURE; @@ -77,7 +77,7 @@ int main(void) { // Try to make QR Code symbol bool ok; if (isAscii) { - char *text = malloc((length + 1) * sizeof(char)); + char *text = malloc((size_t)(length + 1) * sizeof(char)); if (text == NULL) { perror("malloc"); return EXIT_FAILURE; @@ -89,7 +89,7 @@ int main(void) { minVersion, maxVersion, (enum qrcodegen_Mask)mask, boostEcl == 1); free(text); } else if (length <= bufferLen) { - memcpy(tempBuffer, data, length * sizeof(data[0])); + memcpy(tempBuffer, data, (size_t)length * sizeof(data[0])); ok = qrcodegen_encodeBinary(tempBuffer, (size_t)length, qrcode, (enum qrcodegen_Ecc)errCorLvl, minVersion, maxVersion, (enum qrcodegen_Mask)mask, boostEcl == 1); } else diff --git a/c/qrcodegen.c b/c/qrcodegen.c index d899803..612409a 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -132,7 +132,7 @@ bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode size_t textLen = strlen(text); if (textLen == 0) return qrcodegen_encodeSegmentsAdvanced(NULL, 0, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode); - size_t bufLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); + size_t bufLen = (size_t)qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); struct qrcodegen_Segment seg; if (qrcodegen_isNumeric(text)) { @@ -228,14 +228,16 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz } // Concatenate all segments to create the data bit string - memset(qrcode, 0, qrcodegen_BUFFER_LEN_FOR_VERSION(version) * sizeof(qrcode[0])); + memset(qrcode, 0, (size_t)qrcodegen_BUFFER_LEN_FOR_VERSION(version) * sizeof(qrcode[0])); int bitLen = 0; for (size_t i = 0; i < len; i++) { const struct qrcodegen_Segment *seg = &segs[i]; - appendBitsToBuffer((int)seg->mode, 4, qrcode, &bitLen); - appendBitsToBuffer(seg->numChars, numCharCountBits(seg->mode, version), qrcode, &bitLen); - for (int j = 0; j < seg->bitLength; j++) - appendBitsToBuffer((seg->data[j >> 3] >> (7 - (j & 7))) & 1, 1, qrcode, &bitLen); + appendBitsToBuffer((unsigned int)seg->mode, 4, qrcode, &bitLen); + appendBitsToBuffer((unsigned int)seg->numChars, numCharCountBits(seg->mode, version), qrcode, &bitLen); + for (int j = 0; j < seg->bitLength; j++) { + int bit = (seg->data[j >> 3] >> (7 - (j & 7))) & 1; + appendBitsToBuffer((unsigned int)bit, 1, qrcode, &bitLen); + } } assert(bitLen == dataUsedBits); @@ -356,7 +358,7 @@ testable void reedSolomonComputeDivisor(int degree, uint8_t result[]) { assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX); // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1. // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array {255, 8, 93}. - memset(result, 0, degree * sizeof(result[0])); + memset(result, 0, (size_t)degree * sizeof(result[0])); result[degree - 1] = 1; // Start off with the monomial x^0 // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), @@ -381,10 +383,10 @@ testable void reedSolomonComputeDivisor(int degree, uint8_t result[]) { testable void reedSolomonComputeRemainder(const uint8_t data[], int dataLen, const uint8_t generator[], int degree, uint8_t result[]) { assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX); - memset(result, 0, degree * sizeof(result[0])); + memset(result, 0, (size_t)degree * sizeof(result[0])); for (int i = 0; i < dataLen; i++) { // Polynomial division uint8_t factor = data[i] ^ result[0]; - memmove(&result[0], &result[1], (degree - 1) * sizeof(result[0])); + memmove(&result[0], &result[1], (size_t)(degree - 1) * sizeof(result[0])); result[degree - 1] = 0; for (int j = 0; j < degree; j++) result[j] ^= reedSolomonMultiply(generator[j], factor); @@ -400,7 +402,7 @@ testable uint8_t reedSolomonMultiply(uint8_t x, uint8_t y) { // Russian peasant multiplication uint8_t z = 0; for (int i = 7; i >= 0; i--) { - z = (z << 1) ^ ((z >> 7) * 0x11D); + z = (uint8_t)((z << 1) ^ ((z >> 7) * 0x11D)); z ^= ((y >> i) & 1) * x; } return z; @@ -415,7 +417,7 @@ testable uint8_t reedSolomonMultiply(uint8_t x, uint8_t y) { testable void initializeFunctionModules(int version, uint8_t qrcode[]) { // Initialize QR Code int qrsize = version * 4 + 17; - memset(qrcode, 0, ((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0])); + memset(qrcode, 0, (size_t)((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0])); qrcode[0] = (uint8_t)qrsize; // Fill horizontal and vertical timing patterns @@ -551,7 +553,7 @@ testable int getAlignmentPatternPositions(int version, uint8_t result[7]) { int step = (version == 32) ? 26 : (version*4 + numAlign*2 + 1) / (numAlign*2 - 2) * 2; for (int i = numAlign - 1, pos = version * 4 + 10; i >= 1; i--, pos -= step) - result[i] = pos; + result[i] = (uint8_t)pos; result[0] = 6; return numAlign; } @@ -962,16 +964,16 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]) { assert(false); else if (assignVal < (1 << 7)) { memset(buf, 0, 1 * sizeof(buf[0])); - appendBitsToBuffer(assignVal, 8, buf, &result.bitLength); + appendBitsToBuffer((unsigned int)assignVal, 8, buf, &result.bitLength); } else if (assignVal < (1 << 14)) { memset(buf, 0, 2 * sizeof(buf[0])); appendBitsToBuffer(2, 2, buf, &result.bitLength); - appendBitsToBuffer(assignVal, 14, buf, &result.bitLength); + appendBitsToBuffer((unsigned int)assignVal, 14, buf, &result.bitLength); } else if (assignVal < 1000000L) { memset(buf, 0, 3 * sizeof(buf[0])); appendBitsToBuffer(6, 3, buf, &result.bitLength); - appendBitsToBuffer(assignVal >> 10, 11, buf, &result.bitLength); - appendBitsToBuffer(assignVal & 0x3FF, 10, buf, &result.bitLength); + appendBitsToBuffer((unsigned int)(assignVal >> 10), 11, buf, &result.bitLength); + appendBitsToBuffer((unsigned int)(assignVal & 0x3FF), 10, buf, &result.bitLength); } else assert(false); result.data = buf; From 68d4cb52173d97c369248999f80eca7e01696ec8 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:07:09 +0000 Subject: [PATCH 06/12] Clarified C qrcodegen-test addEccAndInterleaveReference() so that its internals use size_t instead of int. --- c/qrcodegen-test.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index 30bb318..0db1b29 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -107,30 +107,30 @@ static void testAppendBitsToBuffer(void) { // Ported from the Java version of the code. static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, enum qrcodegen_Ecc ecl) { // Calculate parameter numbers - int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; - int blockEccLen = ECC_CODEWORDS_PER_BLOCK[(int)ecl][version]; - int rawCodewords = getNumRawDataModules(version) / 8; - int numShortBlocks = numBlocks - rawCodewords % numBlocks; - int shortBlockLen = rawCodewords / numBlocks; + size_t numBlocks = (size_t)NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; + size_t blockEccLen = (size_t)ECC_CODEWORDS_PER_BLOCK[(int)ecl][version]; + size_t rawCodewords = (size_t)getNumRawDataModules(version) / 8; + size_t numShortBlocks = numBlocks - rawCodewords % numBlocks; + size_t shortBlockLen = rawCodewords / numBlocks; // Split data into blocks and append ECC to each block - uint8_t **blocks = malloc((size_t)numBlocks * sizeof(uint8_t*)); - uint8_t *generator = malloc((size_t)blockEccLen * sizeof(uint8_t)); - reedSolomonComputeDivisor(blockEccLen, generator); - for (int i = 0, k = 0; i < numBlocks; i++) { - uint8_t *block = malloc((size_t)(shortBlockLen + 1) * sizeof(uint8_t)); - int datLen = shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1); - memcpy(block, &data[k], (size_t)datLen * sizeof(uint8_t)); - reedSolomonComputeRemainder(&data[k], datLen, generator, blockEccLen, &block[shortBlockLen + 1 - blockEccLen]); + uint8_t **blocks = malloc(numBlocks * sizeof(uint8_t*)); + uint8_t *generator = malloc(blockEccLen * sizeof(uint8_t)); + reedSolomonComputeDivisor((int)blockEccLen, generator); + for (size_t i = 0, k = 0; i < numBlocks; i++) { + uint8_t *block = malloc((shortBlockLen + 1) * sizeof(uint8_t)); + size_t datLen = shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1); + memcpy(block, &data[k], datLen * sizeof(uint8_t)); + reedSolomonComputeRemainder(&data[k], (int)datLen, generator, (int)blockEccLen, &block[shortBlockLen + 1 - blockEccLen]); k += datLen; blocks[i] = block; } free(generator); // Interleave (not concatenate) the bytes from every block into a single sequence - uint8_t *result = malloc((size_t)rawCodewords * sizeof(uint8_t)); - for (int i = 0, k = 0; i < shortBlockLen + 1; i++) { - for (int j = 0; j < numBlocks; j++) { + uint8_t *result = malloc(rawCodewords * sizeof(uint8_t)); + for (size_t i = 0, k = 0; i < shortBlockLen + 1; i++) { + for (size_t j = 0; j < numBlocks; j++) { // Skip the padding byte in short blocks if (i != shortBlockLen - blockEccLen || j >= numShortBlocks) { result[k] = blocks[j][i]; @@ -138,7 +138,7 @@ static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, e } } } - for (int i = 0; i < numBlocks; i++) + for (size_t i = 0; i < numBlocks; i++) free(blocks[i]); free(blocks); return result; From ae0ff71ff1066a09afa5ff000f4d6561ff46e7b9 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:26:56 +0000 Subject: [PATCH 07/12] Clarified C qrcodegen-test testAddEccAndInterleave() so that its internals use size_t instead of int. --- c/qrcodegen-test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index 0db1b29..0992a41 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -148,19 +148,19 @@ static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, e static void testAddEccAndInterleave(void) { for (int version = 1; version <= 40; version++) { for (int ecl = 0; ecl < 4; ecl++) { - int dataLen = getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl); - uint8_t *pureData = malloc((size_t)dataLen * sizeof(uint8_t)); - for (int i = 0; i < dataLen; i++) + size_t dataLen = (size_t)getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl); + uint8_t *pureData = malloc(dataLen * sizeof(uint8_t)); + for (size_t i = 0; i < dataLen; i++) pureData[i] = (uint8_t)(rand() % 256); uint8_t *expectOutput = addEccAndInterleaveReference(pureData, version, (enum qrcodegen_Ecc)ecl); - int dataAndEccLen = getNumRawDataModules(version) / 8; - uint8_t *paddedData = malloc((size_t)dataAndEccLen * sizeof(uint8_t)); - memcpy(paddedData, pureData, (size_t)dataLen * sizeof(uint8_t)); - uint8_t *actualOutput = malloc((size_t)dataAndEccLen * sizeof(uint8_t)); + size_t dataAndEccLen = (size_t)getNumRawDataModules(version) / 8; + uint8_t *paddedData = malloc(dataAndEccLen * sizeof(uint8_t)); + memcpy(paddedData, pureData, dataLen * sizeof(uint8_t)); + uint8_t *actualOutput = malloc(dataAndEccLen * sizeof(uint8_t)); addEccAndInterleave(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput); - assert(memcmp(actualOutput, expectOutput, (size_t)dataAndEccLen * sizeof(uint8_t)) == 0); + assert(memcmp(actualOutput, expectOutput, dataAndEccLen * sizeof(uint8_t)) == 0); free(pureData); free(expectOutput); free(paddedData); From a492346364a40eb931865a5d0e550d6137ff5657 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:30:40 +0000 Subject: [PATCH 08/12] Clarified C qrcodegen-worker so that two internal variables use size_t instead of int. --- c/qrcodegen-worker.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/c/qrcodegen-worker.c b/c/qrcodegen-worker.c index b41a037..51678bb 100644 --- a/c/qrcodegen-worker.c +++ b/c/qrcodegen-worker.c @@ -39,20 +39,24 @@ int main(void) { while (true) { // Read data length or exit - int length; - if (scanf("%d", &length) != 1) - return EXIT_FAILURE; - if (length == -1) - break; + size_t length; + { + int temp; + if (scanf("%d", &temp) != 1) + return EXIT_FAILURE; + if (temp == -1) + break; + length = (size_t)temp; + } // Read data bytes bool isAscii = true; - uint8_t *data = malloc((size_t)length * sizeof(uint8_t)); + uint8_t *data = malloc(length * sizeof(uint8_t)); if (data == NULL) { perror("malloc"); return EXIT_FAILURE; } - for (int i = 0; i < length; i++) { + for (size_t i = 0; i < length; i++) { int b; if (scanf("%d", &b) != 1) return EXIT_FAILURE; @@ -66,9 +70,9 @@ int main(void) { return EXIT_FAILURE; // Allocate memory for QR Code - int bufferLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); - uint8_t *qrcode = malloc((size_t)bufferLen * sizeof(uint8_t)); - uint8_t *tempBuffer = malloc((size_t)bufferLen * sizeof(uint8_t)); + size_t bufferLen = (size_t)qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); + uint8_t *qrcode = malloc(bufferLen * sizeof(uint8_t)); + uint8_t *tempBuffer = malloc(bufferLen * sizeof(uint8_t)); if (qrcode == NULL || tempBuffer == NULL) { perror("malloc"); return EXIT_FAILURE; @@ -77,20 +81,20 @@ int main(void) { // Try to make QR Code symbol bool ok; if (isAscii) { - char *text = malloc((size_t)(length + 1) * sizeof(char)); + char *text = malloc((length + 1) * sizeof(char)); if (text == NULL) { perror("malloc"); return EXIT_FAILURE; } - for (int i = 0; i < length; i++) + for (size_t i = 0; i < length; i++) text[i] = (char)data[i]; text[length] = '\0'; ok = qrcodegen_encodeText(text, tempBuffer, qrcode, (enum qrcodegen_Ecc)errCorLvl, minVersion, maxVersion, (enum qrcodegen_Mask)mask, boostEcl == 1); free(text); } else if (length <= bufferLen) { - memcpy(tempBuffer, data, (size_t)length * sizeof(data[0])); - ok = qrcodegen_encodeBinary(tempBuffer, (size_t)length, qrcode, (enum qrcodegen_Ecc)errCorLvl, + memcpy(tempBuffer, data, length * sizeof(data[0])); + ok = qrcodegen_encodeBinary(tempBuffer, length, qrcode, (enum qrcodegen_Ecc)errCorLvl, minVersion, maxVersion, (enum qrcodegen_Mask)mask, boostEcl == 1); } else ok = false; From 42f753cfcf7d5d5540c51203b944aaf5c4646d78 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:31:19 +0000 Subject: [PATCH 09/12] Fixed indentation in a line of C code. --- c/qrcodegen-worker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/qrcodegen-worker.c b/c/qrcodegen-worker.c index 51678bb..dc16888 100644 --- a/c/qrcodegen-worker.c +++ b/c/qrcodegen-worker.c @@ -59,7 +59,7 @@ int main(void) { for (size_t i = 0; i < length; i++) { int b; if (scanf("%d", &b) != 1) - return EXIT_FAILURE; + return EXIT_FAILURE; data[i] = (uint8_t)b; isAscii &= 0 < b && b < 128; } From 1a254cf67fc2e9cb62c883b60b68775bfbf43232 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:44:19 +0000 Subject: [PATCH 10/12] Refactored C qrcodegen-test's testCalcSegmentBitLength() to add a test case struct. --- c/qrcodegen-test.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index 0992a41..4648dcf 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -694,8 +694,12 @@ static void testCalcSegmentBufferSize(void) { static void testCalcSegmentBitLength(void) { + struct TestCase { + size_t numChars; + int result; + }; { - const int cases[][2] = { + const struct TestCase CASES[] = { {0, 0}, {1, 4}, {2, 7}, @@ -717,13 +721,13 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 2, -1}, {INT_MAX / 1, -1}, }; - for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_NUMERIC, (size_t)cases[i][0]) == cases[i][1]); + for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { + assert(calcSegmentBitLength(qrcodegen_Mode_NUMERIC, CASES[i].numChars) == CASES[i].result); numTestCases++; } } { - const int cases[][2] = { + const struct TestCase CASES[] = { {0, 0}, {1, 6}, {2, 11}, @@ -747,13 +751,13 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 2, -1}, {INT_MAX / 1, -1}, }; - for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_ALPHANUMERIC, (size_t)cases[i][0]) == cases[i][1]); + for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { + assert(calcSegmentBitLength(qrcodegen_Mode_ALPHANUMERIC, CASES[i].numChars) == CASES[i].result); numTestCases++; } } { - const int cases[][2] = { + const struct TestCase CASES[] = { {0, 0}, {1, 8}, {2, 16}, @@ -776,13 +780,13 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 2, -1}, {INT_MAX / 1, -1}, }; - for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_BYTE, (size_t)cases[i][0]) == cases[i][1]); + for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { + assert(calcSegmentBitLength(qrcodegen_Mode_BYTE, CASES[i].numChars) == CASES[i].result); numTestCases++; } } { - const int cases[][2] = { + const struct TestCase CASES[] = { {0, 0}, {1, 13}, {2, 26}, @@ -804,8 +808,8 @@ static void testCalcSegmentBitLength(void) { {INT_MAX / 2, -1}, {INT_MAX / 1, -1}, }; - for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) { - assert(calcSegmentBitLength(qrcodegen_Mode_KANJI, (size_t)cases[i][0]) == cases[i][1]); + for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { + assert(calcSegmentBitLength(qrcodegen_Mode_KANJI, CASES[i].numChars) == CASES[i].result); numTestCases++; } } From 0ebd221a2727fce6b7506ff6f6764f5bef14a3e4 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:56:28 +0000 Subject: [PATCH 11/12] Updated C test suite for an internal function because the parameter is size_t and not int. (The function and test were introduced in commit 08108ee6d8ae.) --- c/qrcodegen-test.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index 4648dcf..37612d7 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -717,9 +717,10 @@ static void testCalcSegmentBitLength(void) { {9832, -1}, {12000, -1}, {28453, -1}, - {INT_MAX / 3, -1}, - {INT_MAX / 2, -1}, - {INT_MAX / 1, -1}, + {SIZE_MAX / 6, -1}, + {SIZE_MAX / 3, -1}, + {SIZE_MAX / 2, -1}, + {SIZE_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { assert(calcSegmentBitLength(qrcodegen_Mode_NUMERIC, CASES[i].numChars) == CASES[i].result); @@ -745,11 +746,10 @@ static void testCalcSegmentBitLength(void) { {5959, -1}, {12000, -1}, {28453, -1}, - {INT_MAX / 5, -1}, - {INT_MAX / 4, -1}, - {INT_MAX / 3, -1}, - {INT_MAX / 2, -1}, - {INT_MAX / 1, -1}, + {SIZE_MAX / 10, -1}, + {SIZE_MAX / 5, -1}, + {SIZE_MAX / 2, -1}, + {SIZE_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { assert(calcSegmentBitLength(qrcodegen_Mode_ALPHANUMERIC, CASES[i].numChars) == CASES[i].result); @@ -771,14 +771,11 @@ static void testCalcSegmentBitLength(void) { {5957, -1}, {12000, -1}, {28453, -1}, - {INT_MAX / 8 + 1, -1}, - {INT_MAX / 7, -1}, - {INT_MAX / 6, -1}, - {INT_MAX / 5, -1}, - {INT_MAX / 4, -1}, - {INT_MAX / 3, -1}, - {INT_MAX / 2, -1}, - {INT_MAX / 1, -1}, + {SIZE_MAX / 15, -1}, + {SIZE_MAX / 12, -1}, + {SIZE_MAX / 7, -1}, + {SIZE_MAX / 3, -1}, + {SIZE_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { assert(calcSegmentBitLength(qrcodegen_Mode_BYTE, CASES[i].numChars) == CASES[i].result); @@ -800,13 +797,12 @@ static void testCalcSegmentBitLength(void) { {2522, -1}, {12000, -1}, {28453, -1}, - {INT_MAX / 13 + 1, -1}, - {INT_MAX / 12, -1}, - {INT_MAX / 9, -1}, - {INT_MAX / 4, -1}, - {INT_MAX / 3, -1}, - {INT_MAX / 2, -1}, - {INT_MAX / 1, -1}, + {SIZE_MAX / 25, -1}, + {SIZE_MAX / 20, -1}, + {SIZE_MAX / 11, -1}, + {SIZE_MAX / 4, -1}, + {SIZE_MAX / 2, -1}, + {SIZE_MAX / 1, -1}, }; for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) { assert(calcSegmentBitLength(qrcodegen_Mode_KANJI, CASES[i].numChars) == CASES[i].result); From 5efbdc48223d4922f052327c93ea509bce92061d Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 22 Jul 2019 17:57:06 +0000 Subject: [PATCH 12/12] Added whitespace to align some code. --- cpp/QrCode.cpp | 2 +- typescript/qrcodegen.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index e6a287d..e169174 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -325,7 +325,7 @@ void QrCode::drawAlignmentPattern(int x, int y) { void QrCode::setFunctionModule(int x, int y, bool isBlack) { size_t ux = static_cast(x); size_t uy = static_cast(y); - modules.at(uy).at(ux) = isBlack; + modules .at(uy).at(ux) = isBlack; isFunction.at(uy).at(ux) = true; } diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 3e436b6..a7f0ab4 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -26,9 +26,9 @@ namespace qrcodegen { - type bit = number; + type bit = number; type byte = number; - type int = number; + type int = number; /*---- QR Code symbol class ----*/