Get rid of "exceptions" in CBC_QRCoderBitVector::At(). Replace it with a CHECK() that should not fail since all the existing callers check the bit vector's size. Change-Id: Id90ca612766661959c7879754dc34ad401402fbd Reviewed-on: https://pdfium-review.googlesource.com/c/45767 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.cpp b/fxbarcode/qrcode/BC_QRCoderBitVector.cpp index 7a41ad0..09dddc3 100644 --- a/fxbarcode/qrcode/BC_QRCoderBitVector.cpp +++ b/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
@@ -25,15 +25,12 @@ #include "core/fxcrt/fx_memory.h" #include "fxbarcode/utils.h" -CBC_QRCoderBitVector::CBC_QRCoderBitVector() {} +CBC_QRCoderBitVector::CBC_QRCoderBitVector() = default; -CBC_QRCoderBitVector::~CBC_QRCoderBitVector() {} +CBC_QRCoderBitVector::~CBC_QRCoderBitVector() = default; -int32_t CBC_QRCoderBitVector::At(size_t index, int32_t& e) const { - if (index >= m_sizeInBits) { - e = BCExceptionBadIndexException; - return 0; - } +int32_t CBC_QRCoderBitVector::At(size_t index) const { + CHECK(index < m_sizeInBits); int32_t value = m_array[index >> 3] & 0xff; return (value >> (7 - (index & 0x7))) & 1; } @@ -73,14 +70,9 @@ } } -void CBC_QRCoderBitVector::AppendBitVector(CBC_QRCoderBitVector* bits) { - int32_t size = bits->Size(); - for (int32_t i = 0; i < size; i++) { - int e = BCExceptionNO; - int32_t num = bits->At(i, e); - ASSERT(e == BCExceptionNO); - AppendBit(num); - } +void CBC_QRCoderBitVector::AppendBitVector(const CBC_QRCoderBitVector* bits) { + for (size_t i = 0; i < bits->Size(); i++) + AppendBit(bits->At(i)); } bool CBC_QRCoderBitVector::XOR(const CBC_QRCoderBitVector* other) {
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.h b/fxbarcode/qrcode/BC_QRCoderBitVector.h index 0ebeb60..9b8af81 100644 --- a/fxbarcode/qrcode/BC_QRCoderBitVector.h +++ b/fxbarcode/qrcode/BC_QRCoderBitVector.h
@@ -18,13 +18,13 @@ ~CBC_QRCoderBitVector(); const uint8_t* GetArray() const; - int32_t At(size_t index, int32_t& e) const; + int32_t At(size_t index) const; size_t Size() const; size_t sizeInBytes() const; void AppendBit(int32_t bit); void AppendBits(int32_t value, int32_t numBits); - void AppendBitVector(CBC_QRCoderBitVector* bits); + void AppendBitVector(const CBC_QRCoderBitVector* bits); bool XOR(const CBC_QRCoderBitVector* other); private:
diff --git a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp index 2a13ade..59d275f 100644 --- a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp +++ b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
@@ -96,7 +96,7 @@ int32_t maskPattern, CBC_CommonByteMatrix* matrix) { int32_t e = BCExceptionNO; - size_t bitIndex = 0; + size_t szBitIndex = 0; int32_t direction = -1; int32_t x = matrix->GetWidth() - 1; int32_t y = matrix->GetHeight() - 1; @@ -115,11 +115,9 @@ continue; } int32_t bit; - if (bitIndex < dataBits->Size()) { - bit = dataBits->At(bitIndex, e); - if (e != BCExceptionNO) - return false; - bitIndex++; + if (szBitIndex < dataBits->Size()) { + bit = dataBits->At(szBitIndex); + szBitIndex++; } else { bit = 0; } @@ -139,7 +137,7 @@ y += direction; x -= 2; } - return bitIndex == dataBits->Size(); + return szBitIndex == dataBits->Size(); } int32_t CalculateBCHCode(int32_t value, int32_t poly) { @@ -184,11 +182,8 @@ if (!MakeTypeInfoBits(ecLevel, maskPattern, &typeInfoBits)) return false; - int32_t e = BCExceptionNO; for (size_t i = 0; i < typeInfoBits.Size(); i++) { - int32_t bit = typeInfoBits.At(typeInfoBits.Size() - 1 - i, e); - if (e != BCExceptionNO) - return false; + int32_t bit = typeInfoBits.At(typeInfoBits.Size() - 1 - i); int32_t x1 = TYPE_INFO_COORDINATES[i][0]; int32_t y1 = TYPE_INFO_COORDINATES[i][1]; matrix->Set(x1, y1, bit); @@ -205,25 +200,21 @@ return true; } -bool MaybeEmbedVersionInfo(int32_t version, CBC_CommonByteMatrix* matrix) { +void MaybeEmbedVersionInfo(int32_t version, CBC_CommonByteMatrix* matrix) { if (version < 7) - return true; + return; CBC_QRCoderBitVector versionInfoBits; MakeVersionInfoBits(version, &versionInfoBits); int32_t bitIndex = 6 * 3 - 1; - int32_t e = BCExceptionNO; for (int32_t i = 0; i < 6; i++) { for (int32_t j = 0; j < 3; j++) { - int32_t bit = versionInfoBits.At(bitIndex, e); - if (e != BCExceptionNO) - return false; + int32_t bit = versionInfoBits.At(bitIndex); bitIndex--; matrix->Set(i, matrix->GetHeight() - 11 + j, bit); matrix->Set(matrix->GetHeight() - 11 + j, i, bit); } } - return true; } bool EmbedTimingPatterns(CBC_CommonByteMatrix* matrix) { @@ -396,9 +387,7 @@ return false; if (!EmbedTypeInfo(ecLevel, maskPattern, matrix)) return false; - if (!MaybeEmbedVersionInfo(version, matrix)) - return false; - if (!EmbedDataBits(dataBits, maskPattern, matrix)) - return false; - return true; + + MaybeEmbedVersionInfo(version, matrix); + return EmbedDataBits(dataBits, maskPattern, matrix); }
diff --git a/fxbarcode/utils.h b/fxbarcode/utils.h index 94e7266..7d41e91 100644 --- a/fxbarcode/utils.h +++ b/fxbarcode/utils.h
@@ -25,7 +25,6 @@ #define BCExceptionNO 0 #define BCExceptionIllegalArgument 16 #define BCExceptionValueMustBeEither0or1 50 -#define BCExceptionBadIndexException 52 #define BCExceptionInvalidateMaskPattern 68 #define BCExceptionCharacterNotThisMode 75 #define BCExceptionGeneric 107