diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 0864ee2..bad055a 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -120,21 +120,17 @@ QrCode QrCode::encodeSegments(const vector &segs, Ecc ecl, QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) : - // Initialize scalar fields + // Initialize fields version(ver), size(1 <= ver && ver <= 40 ? ver * 4 + 17 : -1), // Avoid signed overflow undefined behavior - errorCorrectionLevel(ecl) { + errorCorrectionLevel(ecl), + modules(size, vector(size)), // Entirely white grid + isFunction(size, vector(size)) { // Check arguments if (ver < 1 || ver > 40 || mask < -1 || mask > 7) throw "Value out of range"; - vector row(size); - for (int i = 0; i < size; i++) { - modules.push_back(row); - isFunction.push_back(row); - } - // Draw function patterns, draw all codewords, do masking drawFunctionPatterns(); const vector allCodewords(appendErrorCorrection(dataCodewords)); @@ -147,16 +143,15 @@ QrCode::QrCode(const QrCode &qr, int mask) : // Copy scalar fields version(qr.version), size(qr.size), - errorCorrectionLevel(qr.errorCorrectionLevel) { + errorCorrectionLevel(qr.errorCorrectionLevel), + // Handle grid fields + modules(qr.modules), + isFunction(qr.isFunction) { // Check arguments if (mask < -1 || mask > 7) throw "Mask value out of range"; - // Handle grid fields - modules = qr.modules; - isFunction = qr.isFunction; - // Handle masking applyMask(qr.mask); // Undo old mask this->mask = handleConstructorMasking(mask);