diff options
author | weili <weili@chromium.org> | 2016-06-02 15:48:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-02 15:48:16 -0700 |
commit | db444d2063df6c574882d9263e885c4fe1134133 (patch) | |
tree | 27ce4a3f181ae0b5ad4eff6893016e7d49dfce0a /core/fpdfapi | |
parent | ad700c2c1fc3c3843dae71e5982f462e42efc987 (diff) | |
download | pdfium-db444d2063df6c574882d9263e885c4fe1134133.tar.xz |
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
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_cidfont.cpp | 19 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 35 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp | 38 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp | 14 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 11 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 6 |
7 files changed, 52 insertions, 77 deletions
diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index 994c1c8a5a..0a833a4835 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -779,11 +779,11 @@ FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, FX_CHAR offset_buf[20]; FXSYS_memset(offset_buf, 0, sizeof(offset_buf)); FXSYS_i64toa(m_PrevOffset, offset_buf, 10); - int32_t len = (int32_t)FXSYS_strlen(offset_buf); - if (pFile->AppendBlock(offset_buf, len) < 0) { + int32_t offset_len = (int32_t)FXSYS_strlen(offset_buf); + if (pFile->AppendBlock(offset_buf, offset_len) < 0) { return FALSE; } - offset += len + 6; + offset += offset_len + 6; } FX_BOOL bPredictor = TRUE; CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), TRUE, diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp index cde28fd534..194db8b25c 100644 --- a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp @@ -682,17 +682,17 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { if (!name) { return charcode == 0 ? -1 : (int)charcode; } - uint16_t unicode = PDF_UnicodeFromAdobeName(name); - if (unicode) { + uint16_t name_unicode = PDF_UnicodeFromAdobeName(name); + if (name_unicode) { if (bMSUnicode) { - index = FXFT_Get_Char_Index(face, unicode); + index = FXFT_Get_Char_Index(face, name_unicode); } else if (bMacRoman) { uint32_t maccode = - FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, unicode); + FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, name_unicode); index = !maccode ? FXFT_Get_Name_Index(face, (char*)name) : FXFT_Get_Char_Index(face, maccode); } else { - return FXFT_Get_Char_Index(face, unicode); + return FXFT_Get_Char_Index(face, name_unicode); } } else { return charcode == 0 ? -1 : (int)charcode; @@ -815,16 +815,15 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, if (!pObj) continue; - if (CPDF_Array* pArray = pObj->AsArray()) { + if (CPDF_Array* pObjArray = pObj->AsArray()) { if (width_status != 1) return; - for (size_t j = 0; j < pArray->GetCount(); j += nElements) { + for (size_t j = 0; j < pObjArray->GetCount(); j += nElements) { result.Add(first_code); result.Add(first_code); - for (int k = 0; k < nElements; k++) { - result.Add(pArray->GetIntegerAt(j + k)); - } + for (int k = 0; k < nElements; k++) + result.Add(pObjArray->GetIntegerAt(j + k)); first_code++; } width_status = 0; diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 52576043e3..4bd4a4d529 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1139,31 +1139,16 @@ void CPDF_StreamContentParser::Handle_SetFont() { CPDF_Object* CPDF_StreamContentParser::FindResourceObj( const CFX_ByteString& type, const CFX_ByteString& name) { - if (!m_pResources) { - return NULL; - } - if (m_pResources == m_pPageResources) { - CPDF_Dictionary* pList = m_pResources->GetDictBy(type); - if (!pList) { - return NULL; - } - CPDF_Object* pRes = pList->GetDirectObjectBy(name); - return pRes; - } - CPDF_Dictionary* pList = m_pResources->GetDictBy(type); - if (!pList) { - if (!m_pPageResources) { - return NULL; - } - CPDF_Dictionary* pList = m_pPageResources->GetDictBy(type); - if (!pList) { - return NULL; - } - CPDF_Object* pRes = pList->GetDirectObjectBy(name); - return pRes; - } - CPDF_Object* pRes = pList->GetDirectObjectBy(name); - return pRes; + if (!m_pResources) + return nullptr; + CPDF_Dictionary* pDict = m_pResources->GetDictBy(type); + if (pDict) + return pDict->GetDirectObjectBy(name); + if (m_pResources == m_pPageResources || !m_pPageResources) + return nullptr; + + CPDF_Dictionary* pPageDict = m_pPageResources->GetDictBy(type); + return pPageDict ? pPageDict->GetDirectObjectBy(name) : nullptr; } CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) { diff --git a/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp b/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp index 054266765a..a4629dcf6b 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp @@ -430,10 +430,9 @@ FX_BOOL CPDF_SecurityHandler::CheckUserPassword(const uint8_t* password, FXSYS_memset(test, 0, sizeof(test)); FXSYS_memset(tmpkey, 0, sizeof(tmpkey)); FXSYS_memcpy(test, ukey.c_str(), copy_len); - for (int i = 19; i >= 0; i--) { - for (int j = 0; j < key_len; j++) { - tmpkey[j] = key[j] ^ i; - } + for (int32_t i = 19; i >= 0; i--) { + for (int j = 0; j < key_len; j++) + tmpkey[j] = key[j] ^ static_cast<uint8_t>(i); CRYPT_ArcFourCryptBlock(test, 32, tmpkey, key_len); } uint8_t md5[100]; @@ -457,14 +456,13 @@ CFX_ByteString CPDF_SecurityHandler::GetUserPassword(const uint8_t* owner_pass, int32_t key_len) { CFX_ByteString okey = m_pEncryptDict->GetStringBy("O"); uint8_t passcode[32]; - uint32_t i; - for (i = 0; i < 32; i++) { + for (uint32_t i = 0; i < 32; i++) { passcode[i] = i < pass_size ? owner_pass[i] : defpasscode[i - pass_size]; } uint8_t digest[16]; CRYPT_MD5Generate(passcode, 32, digest); if (m_Revision >= 3) { - for (int i = 0; i < 50; i++) { + for (uint32_t i = 0; i < 50; i++) { CRYPT_MD5Generate(digest, 16, digest); } } @@ -485,12 +483,11 @@ CFX_ByteString CPDF_SecurityHandler::GetUserPassword(const uint8_t* owner_pass, if (m_Revision == 2) { CRYPT_ArcFourCryptBlock(okeybuf, okeylen, enckey, key_len); } else { - for (int i = 19; i >= 0; i--) { + for (int32_t i = 19; i >= 0; i--) { uint8_t tempkey[32]; FXSYS_memset(tempkey, 0, sizeof(tempkey)); - for (int j = 0; j < m_KeyLen; j++) { - tempkey[j] = enckey[j] ^ i; - } + for (int j = 0; j < m_KeyLen; j++) + tempkey[j] = enckey[j] ^ static_cast<uint8_t>(i); CRYPT_ArcFourCryptBlock(okeybuf, okeylen, tempkey, key_len); } } @@ -553,30 +550,27 @@ void CPDF_SecurityHandler::OnCreate(CPDF_Dictionary* pEncryptDict, } if (bDefault) { uint8_t passcode[32]; - uint32_t i; - for (i = 0; i < 32; i++) { + for (uint32_t i = 0; i < 32; i++) { passcode[i] = i < owner_size ? owner_pass[i] : defpasscode[i - owner_size]; } uint8_t digest[16]; CRYPT_MD5Generate(passcode, 32, digest); if (m_Revision >= 3) { - for (int i = 0; i < 50; i++) { + for (uint32_t i = 0; i < 50; i++) CRYPT_MD5Generate(digest, 16, digest); - } } uint8_t enckey[32]; FXSYS_memcpy(enckey, digest, key_len); - for (i = 0; i < 32; i++) { + for (uint32_t i = 0; i < 32; i++) { passcode[i] = i < user_size ? user_pass[i] : defpasscode[i - user_size]; } CRYPT_ArcFourCryptBlock(passcode, 32, enckey, key_len); uint8_t tempkey[32]; if (m_Revision >= 3) { - for (i = 1; i <= 19; i++) { - for (int j = 0; j < key_len; j++) { - tempkey[j] = enckey[j] ^ (uint8_t)i; - } + for (uint8_t i = 1; i <= 19; i++) { + for (int j = 0; j < key_len; j++) + tempkey[j] = enckey[j] ^ i; CRYPT_ArcFourCryptBlock(passcode, 32, tempkey, key_len); } } @@ -601,9 +595,9 @@ void CPDF_SecurityHandler::OnCreate(CPDF_Dictionary* pEncryptDict, CRYPT_MD5Finish(md5, digest); CRYPT_ArcFourCryptBlock(digest, 16, m_EncryptKey, key_len); uint8_t tempkey[32]; - for (int i = 1; i <= 19; i++) { + for (uint8_t i = 1; i <= 19; i++) { for (int j = 0; j < key_len; j++) { - tempkey[j] = m_EncryptKey[j] ^ (uint8_t)i; + tempkey[j] = m_EncryptKey[j] ^ i; } CRYPT_ArcFourCryptBlock(digest, 16, tempkey, key_len); } diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp index 13a9972425..0eeb4a1afa 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp @@ -381,7 +381,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) return nullptr; - FX_FILESIZE SavedPos = m_Pos; + FX_FILESIZE SavedObjPos = m_Pos; bool bIsNumber; CFX_ByteString word = GetNextWord(&bIsNumber); if (word.GetLength() == 0) @@ -392,10 +392,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, CFX_ByteString nextword = GetNextWord(&bIsNumber); if (bIsNumber) { CFX_ByteString nextword2 = GetNextWord(nullptr); - if (nextword2 == "R") { - uint32_t objnum = FXSYS_atoui(word.c_str()); - return new CPDF_Reference(pObjList, objnum); - } + if (nextword2 == "R") + return new CPDF_Reference(pObjList, FXSYS_atoui(word.c_str())); } m_Pos = SavedPos; return new CPDF_Number(word.AsStringC()); @@ -492,7 +490,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, } if (word == ">>") - m_Pos = SavedPos; + m_Pos = SavedObjPos; return nullptr; } @@ -505,7 +503,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) return nullptr; - FX_FILESIZE SavedPos = m_Pos; + FX_FILESIZE SavedObjPos = m_Pos; bool bIsNumber; CFX_ByteString word = GetNextWord(&bIsNumber); if (word.GetLength() == 0) @@ -605,7 +603,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( } if (word == ">>") - m_Pos = SavedPos; + m_Pos = SavedObjPos; return nullptr; } diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index e9f5a6d468..7c489a35dc 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -447,12 +447,11 @@ CFX_WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) { if (unicode == 0x1b) { i += 2; while (i < max_chars * 2) { - uint16_t unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) - : (uni_str[i + 1] << 8 | uni_str[i]); + uint16_t unicode2 = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) + : (uni_str[i + 1] << 8 | uni_str[i]); i += 2; - if (unicode == 0x1b) { + if (unicode2 == 0x1b) break; - } } } else { dest_buf[dest_pos++] = unicode; @@ -506,9 +505,9 @@ CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len) { dest_buf2[0] = 0xfe; dest_buf2[1] = 0xff; dest_buf2 += 2; - for (int i = 0; i < len; i++) { + for (int j = 0; j < len; j++) { *dest_buf2++ = pString[i] >> 8; - *dest_buf2++ = (uint8_t)pString[i]; + *dest_buf2++ = (uint8_t)pString[j]; } result.ReleaseBuffer(encLen); return result; diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 75f6a231a4..4071a115df 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -381,7 +381,7 @@ int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { } return ret1; } - FXCODEC_STATUS ret = pJbig2Module->ContinueDecode(m_pJbig2Context, pPause); + ret = pJbig2Module->ContinueDecode(m_pJbig2Context, pPause); if (ret < 0) { m_pCachedBitmap.reset(); m_pGlobalStream.reset(); @@ -864,8 +864,8 @@ void CPDF_DIBSource::LoadPalette() { m_pColorSpace->CountComponents() > 1) { int nComponents = m_pColorSpace->CountComponents(); std::vector<FX_FLOAT> temp_buf(nComponents); - for (int i = 0; i < nComponents; i++) { - temp_buf[i] = *color_value; + for (int k = 0; k < nComponents; k++) { + temp_buf[k] = *color_value; } m_pColorSpace->GetRGB(temp_buf.data(), R, G, B); } else { |