Remove CPDF_Image::GetDocument() nullptr checks
- Remove code where the caller assumes GetDocument() can return null.
- Add a comment to mention GetDocument() never returns nullptr in
cpdf_image.h.
Change-Id: I6e6e02fc39c52dcc2db91550939fc78c5a1a859f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107134
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h
index 04355a9..ebda040 100644
--- a/core/fpdfapi/page/cpdf_image.h
+++ b/core/fpdfapi/page/cpdf_image.h
@@ -36,6 +36,8 @@
RetainPtr<const CPDF_Dictionary> GetDict() const;
RetainPtr<const CPDF_Stream> GetStream() const;
RetainPtr<const CPDF_Dictionary> GetOC() const;
+
+ // Never returns nullptr.
CPDF_Document* GetDocument() const { return m_pDocument; }
int32_t GetPixelHeight() const { return m_Height; }
diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp
index c031502..0511a02 100644
--- a/core/fpdfapi/page/cpdf_imageobject.cpp
+++ b/core/fpdfapi/page/cpdf_imageobject.cpp
@@ -82,10 +82,6 @@
if (!m_pImage)
return;
- auto* pDoc = m_pImage->GetDocument();
- if (!pDoc)
- return;
-
RetainPtr<const CPDF_Stream> pStream = m_pImage->GetStream();
if (!pStream)
return;
@@ -94,6 +90,9 @@
if (!objnum)
return;
+ auto* pDoc = m_pImage->GetDocument();
+ CHECK(pDoc);
+
m_pImage.Reset(); // Clear my reference before asking the cache.
pDoc->MaybePurgeImage(objnum);
}