From db444d2063df6c574882d9263e885c4fe1134133 Mon Sep 17 00:00:00 2001 From: weili Date: Thu, 2 Jun 2016 15:48:15 -0700 Subject: Fix all the code which has duplicate variable declarations When there are duplicate variable declarations, the inner names shadow the outter ones. This is error prone and harder to read. Remove all the instances found by /analyze. BUG=chromium:613623, chromium:427616 Review-Url: https://codereview.chromium.org/2027273002 --- .../datamatrix/BC_DataMatrixDataBlock.cpp | 27 +++++++++------------- xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp | 10 ++++---- 2 files changed, 15 insertions(+), 22 deletions(-) (limited to 'xfa/fxbarcode/datamatrix') diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp index 6b7680d1a8..a41e46afc9 100644 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp +++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp @@ -40,17 +40,15 @@ CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, ECBlocks* ecBlocks = version->GetECBlocks(); int32_t totalBlocks = 0; const CFX_ArrayTemplate& ecBlockArray = ecBlocks->GetECBlocks(); - int32_t i; - for (i = 0; i < ecBlockArray.GetSize(); i++) { + for (int32_t i = 0; i < ecBlockArray.GetSize(); i++) { totalBlocks += ecBlockArray[i]->GetCount(); } std::unique_ptr> result( new CFX_ArrayTemplate()); result->SetSize(totalBlocks); int32_t numResultBlocks = 0; - int32_t j; - for (j = 0; j < ecBlockArray.GetSize(); j++) { - for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) { + for (int32_t j = 0; j < ecBlockArray.GetSize(); j++) { + for (int32_t i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) { int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords(); int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords; CFX_ByteArray codewords; @@ -60,14 +58,11 @@ CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, codewords.SetSize(0); } } - int32_t longerBlocksTotalCodewords = (*result)[0]->GetCodewords()->GetSize(); int32_t longerBlocksNumDataCodewords = - longerBlocksTotalCodewords - ecBlocks->GetECCodewords(); - int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1; + (*result)[0]->GetCodewords()->GetSize() - ecBlocks->GetECCodewords(); int32_t rawCodewordsOffset = 0; - for (i = 0; i < shorterBlocksNumDataCodewords; i++) { - int32_t j; - for (j = 0; j < numResultBlocks; j++) { + for (int32_t i = 0; i < longerBlocksNumDataCodewords - 1; i++) { + for (int32_t j = 0; j < numResultBlocks; j++) { if (rawCodewordsOffset < rawCodewords->GetSize()) { (*result)[j]->GetCodewords()->operator[](i) = (*rawCodewords)[rawCodewordsOffset++]; @@ -76,17 +71,16 @@ CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, } const bool specialVersion = version->GetVersionNumber() == 24; int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks; - for (j = 0; j < numLongerBlocks; j++) { + for (int32_t j = 0; j < numLongerBlocks; j++) { if (rawCodewordsOffset < rawCodewords->GetSize()) { (*result)[j]->GetCodewords()->operator[](longerBlocksNumDataCodewords - 1) = (*rawCodewords)[rawCodewordsOffset++]; } } - int32_t max = (*result)[0]->GetCodewords()->GetSize(); - for (i = longerBlocksNumDataCodewords; i < max; i++) { - int32_t j; - for (j = 0; j < numResultBlocks; j++) { + for (int32_t i = longerBlocksNumDataCodewords; + i < (*result)[0]->GetCodewords()->GetSize(); i++) { + for (int32_t j = 0; j < numResultBlocks; j++) { int32_t iOffset = specialVersion && j > 7 ? i - 1 : i; if (rawCodewordsOffset < rawCodewords->GetSize()) { (*result)[j]->GetCodewords()->operator[](iOffset) = @@ -100,6 +94,7 @@ CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, } return result.release(); } + int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() { return m_numDataCodewords; } diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp index 4276066444..ffa0a4d9d1 100644 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp +++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp @@ -57,13 +57,12 @@ CBC_CommonDecoderResult* CBC_DataMatrixDecoder::Decode( BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); int32_t dataBlocksCount = dataBlocks->GetSize(); int32_t totalBytes = 0; - int32_t i, j; - for (i = 0; i < dataBlocksCount; i++) { + for (int32_t i = 0; i < dataBlocksCount; i++) { totalBytes += (*dataBlocks)[i]->GetNumDataCodewords(); } CFX_ByteArray resultBytes; resultBytes.SetSize(totalBytes); - for (j = 0; j < dataBlocksCount; j++) { + for (int32_t j = 0; j < dataBlocksCount; j++) { CFX_ByteArray* codewordBytes = (*dataBlocks)[j]->GetCodewords(); int32_t numDataCodewords = (*dataBlocks)[j]->GetNumDataCodewords(); CorrectErrors(*codewordBytes, numDataCodewords, e); @@ -74,12 +73,11 @@ CBC_CommonDecoderResult* CBC_DataMatrixDecoder::Decode( delete dataBlocks; return nullptr; } - int32_t i; - for (i = 0; i < numDataCodewords; i++) { + for (int32_t i = 0; i < numDataCodewords; i++) { resultBytes[i * dataBlocksCount + j] = (*codewordBytes)[i]; } } - for (i = 0; i < (dataBlocks->GetSize()); i++) { + for (int32_t i = 0; i < (dataBlocks->GetSize()); i++) { delete (*dataBlocks)[i]; } delete dataBlocks; -- cgit v1.2.3