summaryrefslogtreecommitdiff
path: root/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-09-22 06:06:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-22 06:06:00 +0000
commitc1c7e514e397e01678d513a5331765b40bca59bb (patch)
treed4ca2b943c376da71425b8aceea6cd4952ad30ec /fxbarcode/qrcode/BC_QRCoderEncoder.cpp
parent7330143be7a3dce5fbbe5642cd8e8e3cc77d6baa (diff)
downloadpdfium-c1c7e514e397e01678d513a5331765b40bca59bb.tar.xz
Change CBC_QRCoderMatrixUtil::BuildMatrix() to return a bool.
Fix caller code and remove some impossible to reach code inside CBC_QRCoderMatrixUtil. Change-Id: I3b0cc0750784e806ba4050fb2487675dee4ee8c3 Reviewed-on: https://pdfium-review.googlesource.com/42455 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fxbarcode/qrcode/BC_QRCoderEncoder.cpp')
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 052ad49a05..4d15ca651f 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -38,6 +38,7 @@
#include "fxbarcode/qrcode/BC_QRCoderMatrixUtil.h"
#include "fxbarcode/qrcode/BC_QRCoderMode.h"
#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
+#include "third_party/base/optional.h"
#include "third_party/base/ptr_util.h"
using ModeStringPair = std::pair<CBC_QRCoderMode*, ByteString>;
@@ -249,19 +250,19 @@ int32_t CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) {
CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(matrix);
}
-int32_t ChooseMaskPattern(CBC_QRCoderBitVector* bits,
- const CBC_QRCoderErrorCorrectionLevel* ecLevel,
- int32_t version,
- CBC_CommonByteMatrix* matrix,
- int32_t& e) {
+Optional<int32_t> ChooseMaskPattern(
+ CBC_QRCoderBitVector* bits,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ int32_t version,
+ CBC_CommonByteMatrix* matrix) {
int32_t minPenalty = 65535;
int32_t bestMaskPattern = -1;
for (int32_t maskPattern = 0; maskPattern < CBC_QRCoder::kNumMaskPatterns;
maskPattern++) {
- CBC_QRCoderMatrixUtil::BuildMatrix(bits, ecLevel, version, maskPattern,
- matrix, e);
- if (e != BCExceptionNO)
- return 0;
+ if (!CBC_QRCoderMatrixUtil::BuildMatrix(bits, ecLevel, version, maskPattern,
+ matrix)) {
+ return {};
+ }
int32_t penalty = CalculateMaskPenalty(matrix);
if (penalty < minPenalty) {
minPenalty = penalty;
@@ -494,20 +495,19 @@ bool CBC_QRCoderEncoder::Encode(const WideString& content,
return false;
}
- int32_t e = BCExceptionNO;
auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(
qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth());
- int32_t maskPattern = ChooseMaskPattern(
- &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
- if (e != BCExceptionNO)
+ Optional<int32_t> maskPattern = ChooseMaskPattern(
+ &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get());
+ if (!maskPattern)
return false;
- qrCode->SetMaskPattern(maskPattern);
- CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
- qrCode->GetVersion(),
- qrCode->GetMaskPattern(), matrix.get(), e);
- if (e != BCExceptionNO)
+ qrCode->SetMaskPattern(*maskPattern);
+ if (!CBC_QRCoderMatrixUtil::BuildMatrix(
+ &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(),
+ qrCode->GetMaskPattern(), matrix.get())) {
return false;
+ }
qrCode->SetMatrix(std::move(matrix));
return qrCode->IsValid();