Remove dead code in cpdf_interactiveform.cpp.
Add some assertions that are known to be true. Then remove all the
checks that cannot fail and replace them with asserts. Also rename one
version of FindFont() to make it distinct from the other.
Change-Id: I70743b93cbf9b3b1e9b30600baaf9ccdbe197bfb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73122
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Hui Yingst <nigi@chromium.org>
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index d812b89..bc21e87 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -216,9 +216,6 @@
CPDF_Document* pDocument,
uint8_t charSet,
ByteString* csNameTag) {
- if (!pFormDict)
- return nullptr;
-
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
if (!pDR)
return nullptr;
@@ -257,9 +254,6 @@
bool FindFont(CPDF_Dictionary* pFormDict,
const CPDF_Font* pFont,
ByteString* csNameTag) {
- if (!pFormDict || !pFont)
- return false;
-
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
if (!pDR)
return false;
@@ -286,14 +280,11 @@
return false;
}
-bool FindFont(CPDF_Dictionary* pFormDict,
- CPDF_Document* pDocument,
- ByteString csFontName,
- RetainPtr<CPDF_Font>& pFont,
- ByteString* csNameTag) {
- if (!pFormDict)
- return false;
-
+bool FindFontFromDoc(CPDF_Dictionary* pFormDict,
+ CPDF_Document* pDocument,
+ ByteString csFontName,
+ RetainPtr<CPDF_Font>& pFont,
+ ByteString* csNameTag) {
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
if (!pDR)
return false;
@@ -333,18 +324,14 @@
CPDF_Document* pDocument,
const RetainPtr<CPDF_Font>& pFont,
ByteString* csNameTag) {
- if (!pFont)
- return;
- if (!pFormDict)
- InitDict(pFormDict, pDocument);
+ ASSERT(pFormDict);
+ ASSERT(pFont);
ByteString csTag;
if (FindFont(pFormDict, pFont.Get(), &csTag)) {
*csNameTag = std::move(csTag);
return;
}
- if (!pFormDict)
- InitDict(pFormDict, pDocument);
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
if (!pDR)
@@ -563,8 +550,12 @@
CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
ByteString* csNameTag) {
+ ASSERT(pDocument);
+ ASSERT(csNameTag);
+
if (!pFormDict)
InitDict(pFormDict, pDocument);
+ ASSERT(pFormDict);
uint8_t charSet = GetNativeCharSet();
ByteString csTemp;
@@ -576,7 +567,7 @@
}
ByteString csFontName = GetNativeFontName(charSet, nullptr);
if (!csFontName.IsEmpty() &&
- FindFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) {
+ FindFontFromDoc(pFormDict, pDocument, csFontName, pFont, csNameTag)) {
return pFont;
}
pFont = AddNativeFont(charSet, pDocument);