summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-06-02 15:48:15 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-02 15:48:16 -0700
commitdb444d2063df6c574882d9263e885c4fe1134133 (patch)
tree27ce4a3f181ae0b5ad4eff6893016e7d49dfce0a /core/fpdfapi/fpdf_parser
parentad700c2c1fc3c3843dae71e5982f462e42efc987 (diff)
downloadpdfium-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/fpdf_parser')
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp38
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp14
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp11
3 files changed, 27 insertions, 36 deletions
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;