mirror of
https://github.com/status-im/qzxing.git
synced 2025-02-21 15:18:14 +00:00
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.
This commit is contained in:
parent
f7a06f2e58
commit
0c624d1e9c
@ -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
|
||||
|
@ -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<zxing::byte>(tempVariable >= 0 ? tempVariable : (tempVariable + 256));
|
||||
}
|
||||
|
||||
void append(std::ostream &ost, const char *bufIn, size_t nIn, const char *src);
|
||||
|
@ -206,6 +206,7 @@ void LinesSampler::codewordsToBitMatrix(vector<vector<int> > &codewords, Ref<Bit
|
||||
for (int j = 0; j < (int)codewords[i].size(); j++) {
|
||||
int moduleOffset = j * MODULES_IN_SYMBOL;
|
||||
for (int k = 0; k < MODULES_IN_SYMBOL; k++) {
|
||||
//TODO: Potential unsafe sign check of a bitwise operation.
|
||||
if ((codewords[i][j] & (1 << (MODULES_IN_SYMBOL - k - 1))) > 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) {
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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_
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <zxing/common/Array.h>
|
||||
#include <zxing/common/Types.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -24,6 +25,16 @@ public:
|
||||
ArrayRef<zxing::byte> getDataBytes() { return data_; }
|
||||
|
||||
ArrayRef<zxing::byte> getErrorCorrectionBytes() { return errorCorrection_; }
|
||||
|
||||
BlockPair& operator=(const BlockPair &other) {
|
||||
data_->release();
|
||||
errorCorrection_->release();
|
||||
|
||||
data_ = other.data_;
|
||||
errorCorrection_ = other.errorCorrection_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ Ref<QRCode> 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user