summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdf_doc.cpp19
-rw-r--r--fpdfsdk/fpdf_doc_embeddertest.cpp10
2 files changed, 21 insertions, 8 deletions
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp
index e7b9042479..e79c36e3e0 100644
--- a/fpdfsdk/fpdf_doc.cpp
+++ b/fpdfsdk/fpdf_doc.cpp
@@ -72,13 +72,13 @@ FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
- if (!pDict)
- return nullptr;
-
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+ if (!pDict)
+ return nullptr;
+
CPDF_BookmarkTree tree(pDoc);
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
return FPDFBookmarkFromCPDFDictionary(
@@ -96,11 +96,13 @@ FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void* buffer, unsigned long buflen) {
FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) {
- if (!title || title[0] == 0)
- return nullptr;
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+
+ if (!title || title[0] == 0)
+ return nullptr;
+
CPDF_BookmarkTree tree(pDoc);
size_t len = WideString::WStringLength(title);
WideString encodedTitle = WideString::FromUTF16LE(title, len);
@@ -111,11 +113,13 @@ FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) {
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document,
FPDF_BOOKMARK pDict) {
- if (!pDict)
- return nullptr;
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+
+ if (!pDict)
+ return nullptr;
+
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
CPDF_Dest dest = bookmark.GetDest(pDoc);
if (dest.GetArray())
@@ -132,6 +136,7 @@ FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV
FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) {
if (!pDict)
return nullptr;
+
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
return FPDFActionFromCPDFDictionary(bookmark.GetAction().GetDict());
}
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp
index 3ba86006d0..dc367d8e26 100644
--- a/fpdfsdk/fpdf_doc_embeddertest.cpp
+++ b/fpdfsdk/fpdf_doc_embeddertest.cpp
@@ -247,8 +247,16 @@ TEST_F(FPDFDocEmbeddertest, NoBookmarks) {
unsigned short buf[128];
EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
- // The non-existent top-level bookmark has no children.
+ // NULL argument cases.
+ EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(nullptr, nullptr));
EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(nullptr, nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_Find(nullptr, nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_GetDest(nullptr, nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_GetDest(document(), nullptr));
+ EXPECT_EQ(nullptr, FPDFBookmark_GetAction(nullptr));
}
TEST_F(FPDFDocEmbeddertest, Bookmarks) {