From d45bc20897f918d5383ff4824272398e8ba6d42e Mon Sep 17 00:00:00 2001 From: Bas van Schaik <5082246+sjvs@users.noreply.github.com> Date: Tue, 2 Jul 2019 12:48:45 +0100 Subject: [PATCH 1/6] Create .lgtm.yml to configure LGTM.com C/C++ analysis This file gives LGTM.com how to configure the C/C++ code. It'll figure out the rest of the build command and required dependencies itself. --- .lgtm.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .lgtm.yml diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 0000000..97a3a63 --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,4 @@ +extraction: + cpp: + configure: + command: "qmake -o Makefile CONFIG+=Release src/QZXing.pro" From bbf898fa0ab4dcfc84cf76cab9e745991b1ff2fe Mon Sep 17 00:00:00 2001 From: Bas van Schaik <5082246+sjvs@users.noreply.github.com> Date: Tue, 2 Jul 2019 13:01:16 +0100 Subject: [PATCH 2/6] Update .lgtm.yml From 0c624d1e9cf5cea8bde1a89be64a4ac56a05dca7 Mon Sep 17 00:00:00 2001 From: Nikos Ftylitakis Date: Wed, 3 Jul 2019 14:11:30 +0300 Subject: [PATCH 3/6] Apply fixes suggested by LGTM checks. a) Create assignment operator overloads where copy constructors are already implemented. b) fix possible loss of data in DecodeBitStreamParser due to signedness missmatch. c) during an exception throw, throw an object's instance, not its pointer. --- src/zxing/zxing/ResultMetadata.cpp | 1 + .../zxing/datamatrix/decoder/DecodedBitStreamParser.h | 4 ++-- src/zxing/zxing/pdf417/detector/LinesSampler.cpp | 2 ++ src/zxing/zxing/qrcode/ErrorCorrectionLevel.h | 2 ++ src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp | 7 +++++++ src/zxing/zxing/qrcode/decoder/Mode.h | 1 + src/zxing/zxing/qrcode/decoder/QRMode.cpp | 11 +++++++++++ src/zxing/zxing/qrcode/encoder/BlockPair.h | 11 +++++++++++ src/zxing/zxing/qrcode/encoder/QREncoder.cpp | 2 +- 9 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/zxing/zxing/ResultMetadata.cpp b/src/zxing/zxing/ResultMetadata.cpp index 3a194c1..e0cff23 100644 --- a/src/zxing/zxing/ResultMetadata.cpp +++ b/src/zxing/zxing/ResultMetadata.cpp @@ -105,6 +105,7 @@ std::string ResultMetadata::keyToString(Key key) const case STRUCTURED_APPEND_CODE_COUNT: return "STRUCTURED_APPEND_CODE_COUNT"; case STRUCTURED_APPEND_PARITY: return "STRUCTURED_APPEND_PARITY"; } + return "UNKNOWN"; } } // zxing diff --git a/src/zxing/zxing/datamatrix/decoder/DecodedBitStreamParser.h b/src/zxing/zxing/datamatrix/decoder/DecodedBitStreamParser.h index c6e6614..0980c47 100644 --- a/src/zxing/zxing/datamatrix/decoder/DecodedBitStreamParser.h +++ b/src/zxing/zxing/datamatrix/decoder/DecodedBitStreamParser.h @@ -85,11 +85,11 @@ private: /** * See ISO 16022:2006, Annex B, B.2 */ - char unrandomize255State(int randomizedBase256Codeword, + zxing::byte unrandomize255State(int randomizedBase256Codeword, int base256CodewordPosition) { int pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1; int tempVariable = randomizedBase256Codeword - pseudoRandomNumber; - return (zxing::byte) (tempVariable >= 0 ? tempVariable : (tempVariable + 256)); + return static_cast(tempVariable >= 0 ? tempVariable : (tempVariable + 256)); } void append(std::ostream &ost, const char *bufIn, size_t nIn, const char *src); diff --git a/src/zxing/zxing/pdf417/detector/LinesSampler.cpp b/src/zxing/zxing/pdf417/detector/LinesSampler.cpp index 1ada0f6..03fb4fb 100644 --- a/src/zxing/zxing/pdf417/detector/LinesSampler.cpp +++ b/src/zxing/zxing/pdf417/detector/LinesSampler.cpp @@ -206,6 +206,7 @@ void LinesSampler::codewordsToBitMatrix(vector > &codewords, Ref 0) { matrix->set(moduleOffset + k, i); } @@ -226,6 +227,7 @@ int LinesSampler::calculateClusterNumber(int codeword) { int barNumber = 0; bool blackBar = true; int clusterNumber = 0; + //TODO: Potential unsafe sign check of a bitwise operation. for (int i = 0; i < MODULES_IN_SYMBOL; i++) { if ((codeword & (1 << i)) > 0) { if (!blackBar) { diff --git a/src/zxing/zxing/qrcode/ErrorCorrectionLevel.h b/src/zxing/zxing/qrcode/ErrorCorrectionLevel.h index 77a6ccd..d703734 100644 --- a/src/zxing/zxing/qrcode/ErrorCorrectionLevel.h +++ b/src/zxing/zxing/qrcode/ErrorCorrectionLevel.h @@ -31,6 +31,7 @@ private: int ordinal_; int bits_; std::string name_; + ErrorCorrectionLevel(int inOrdinal, int bits, char const* name); static ErrorCorrectionLevel *FOR_BITS[]; static int N_LEVELS; @@ -41,6 +42,7 @@ public: static ErrorCorrectionLevel H; ErrorCorrectionLevel(const ErrorCorrectionLevel& other); + ErrorCorrectionLevel& operator=(const ErrorCorrectionLevel &other); int ordinal() const; int bits() const; diff --git a/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp b/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp index 277a8b5..d7cc000 100644 --- a/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp +++ b/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp @@ -52,6 +52,13 @@ ErrorCorrectionLevel::operator string const& () const { return name_; } +ErrorCorrectionLevel& ErrorCorrectionLevel::operator=(const ErrorCorrectionLevel &other) +{ + ordinal_ = other.ordinal(); + bits_ = other.bits(); + name_ = other.name(); +} + ErrorCorrectionLevel& ErrorCorrectionLevel::forBits(int bits) { if (bits < 0 || bits >= N_LEVELS) { throw ReaderException("Ellegal error correction level bits"); diff --git a/src/zxing/zxing/qrcode/decoder/Mode.h b/src/zxing/zxing/qrcode/decoder/Mode.h index 98971a5..1215199 100644 --- a/src/zxing/zxing/qrcode/decoder/Mode.h +++ b/src/zxing/zxing/qrcode/decoder/Mode.h @@ -58,6 +58,7 @@ public: int getCharacterCountBits(const Version *version) const; int getBits() const { return bits_; } + Mode& operator=(const Mode& other); bool operator==(const Mode& other); bool operator!=(const Mode& other); diff --git a/src/zxing/zxing/qrcode/decoder/QRMode.cpp b/src/zxing/zxing/qrcode/decoder/QRMode.cpp index d0ac6b5..cdf1c3b 100644 --- a/src/zxing/zxing/qrcode/decoder/QRMode.cpp +++ b/src/zxing/zxing/qrcode/decoder/QRMode.cpp @@ -108,6 +108,17 @@ int Mode::getCharacterCountBits(const Version *version) const } } +Mode& Mode::operator=(const Mode& other) +{ + characterCountBitsForVersions0To9_ = other.characterCountBitsForVersions0To9_; + characterCountBitsForVersions10To26_ = other.characterCountBitsForVersions10To26_; + characterCountBitsForVersions27AndHigher_ = other.characterCountBitsForVersions27AndHigher_; + bits_ = other.bits_; + name_ = other.name_; + + return *this; +} + bool Mode::operator==(const Mode& other) { return ( characterCountBitsForVersions0To9_ == other.characterCountBitsForVersions0To9_ diff --git a/src/zxing/zxing/qrcode/encoder/BlockPair.h b/src/zxing/zxing/qrcode/encoder/BlockPair.h index 08e140c..a1b498e 100644 --- a/src/zxing/zxing/qrcode/encoder/BlockPair.h +++ b/src/zxing/zxing/qrcode/encoder/BlockPair.h @@ -3,6 +3,7 @@ #include #include +#include using namespace std; @@ -24,6 +25,16 @@ public: ArrayRef getDataBytes() { return data_; } ArrayRef getErrorCorrectionBytes() { return errorCorrection_; } + + BlockPair& operator=(const BlockPair &other) { + data_->release(); + errorCorrection_->release(); + + data_ = other.data_; + errorCorrection_ = other.errorCorrection_; + + return *this; + } }; } diff --git a/src/zxing/zxing/qrcode/encoder/QREncoder.cpp b/src/zxing/zxing/qrcode/encoder/QREncoder.cpp index ba45df4..7f28266 100644 --- a/src/zxing/zxing/qrcode/encoder/QREncoder.cpp +++ b/src/zxing/zxing/qrcode/encoder/QREncoder.cpp @@ -79,7 +79,7 @@ Ref Encoder::encode(const std::string& content, ErrorCorrectionLevel &ec version = Version::getVersionForNumber(1); int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, version); if (!willFit(bitsNeeded, version, ecLevel)) { - throw new WriterException("Data too big for requested version"); + throw WriterException("Data too big for requested version"); } } else { version = recommendVersion(ecLevel, mode, headerBits, dataBits); From a9744f9b892debe6f5e2517f0c29376eceec20d1 Mon Sep 17 00:00:00 2001 From: Nikos Ftylitakis Date: Wed, 3 Jul 2019 14:17:37 +0300 Subject: [PATCH 4/6] fix compilation error due to a missing return statement --- src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp b/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp index d7cc000..aeb0c56 100644 --- a/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp +++ b/src/zxing/zxing/qrcode/QRErrorCorrectionLevel.cpp @@ -57,6 +57,8 @@ ErrorCorrectionLevel& ErrorCorrectionLevel::operator=(const ErrorCorrectionLevel ordinal_ = other.ordinal(); bits_ = other.bits(); name_ = other.name(); + + return *this; } ErrorCorrectionLevel& ErrorCorrectionLevel::forBits(int bits) { From d91f80528d57c50c55d90327b337c7a353224042 Mon Sep 17 00:00:00 2001 From: Nikolaos Ftylitakis Date: Wed, 3 Jul 2019 15:18:45 +0300 Subject: [PATCH 5/6] Added LGTM badges Added LGTM badges. Their actual value is calculated once a day, so upon making changes roughly a day must pass to see results. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3eba48..06f6f28 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# qzxing [![Build Status](https://travis-ci.com/ftylitak/qzxing.svg?branch=master)](https://travis-ci.com/ftylitak/qzxing) [![Build Status](https://ci.appveyor.com/api/projects/status/0033p4dyo49iy5jq?svg=true)](https://ci.appveyor.com/project/ftylitak/qzxing) +# qzxing [![Build Status](https://travis-ci.com/ftylitak/qzxing.svg?branch=master)](https://travis-ci.com/ftylitak/qzxing) [![Build Status](https://ci.appveyor.com/api/projects/status/0033p4dyo49iy5jq?svg=true)](https://ci.appveyor.com/project/ftylitak/qzxing) [![Total alerts](https://img.shields.io/lgtm/alerts/g/ftylitak/qzxing.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ftylitak/qzxing/alerts/) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/ftylitak/qzxing.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ftylitak/qzxing/context:cpp) Qt/QML wrapper library for the [ZXing](https://github.com/zxing/zxing) barcode image processing library. Supports barcode decoding for the following types: From 191f636d3daa390f7f677071d36b47d47a16c70f Mon Sep 17 00:00:00 2001 From: Nikolaos Ftylitakis Date: Wed, 3 Jul 2019 15:21:13 +0300 Subject: [PATCH 6/6] Deactivate Android build checks from Travis After some changes from the Qt installers (? maybe), all Travis Android builds are not able to be configured in order to run. Deactivating thier build till it get fixed. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96af1b6..3535dff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,11 +25,11 @@ addons: env: matrix: - BUILD_TARGERT="linux" QT_VERSION_DIR=5.13 QT_VERSION=5.13.0 - - BUILD_TARGERT="android_armv7" QT_VERSION_DIR=5.13 QT_VERSION=5.13.0 + # - BUILD_TARGERT="android_armv7" QT_VERSION_DIR=5.13 QT_VERSION=5.13.0 - BUILD_TARGERT="linux" QT_VERSION_DIR=5.12 QT_VERSION=5.12.4 - - BUILD_TARGERT="android_armv7" QT_VERSION_DIR=5.12 QT_VERSION=5.12.4 + # - BUILD_TARGERT="android_armv7" QT_VERSION_DIR=5.12 QT_VERSION=5.12.4 - BUILD_TARGERT="linux" QT_VERSION_DIR=5.9 QT_VERSION=5.9.8 - - BUILD_TARGERT="android_armv7" QT_VERSION_DIR=5.9 QT_VERSION=5.9.8 + # - BUILD_TARGERT="android_armv7" QT_VERSION_DIR=5.9 QT_VERSION=5.9.8 before_install: - echo "TRAVIS_OS_NAME=${TRAVIS_OS_NAME}"