Simplify some FPDF edit functions.
Fix an unlikely memory leak in FPDFPage_InsertObject().
BUG=pdfium:545
Review-Url: https://codereview.chromium.org/2195643002
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index 4429dcd..b2c2577 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -17,9 +17,9 @@
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+
CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
- CPDF_Image* pImg = new CPDF_Image(pDoc);
- pImageObj->m_pImage = pImg;
+ pImageObj->m_pImage = new CPDF_Image(pDoc);
return pImageObj;
}
@@ -32,13 +32,12 @@
return FALSE;
IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
- CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+ CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
pImgObj->m_GeneralState.GetModify();
for (int index = 0; index < nCount; index++) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
- if (!pPage)
- continue;
- pImgObj->m_pImage->ResetCache(pPage, nullptr);
+ if (pPage)
+ pImgObj->m_pImage->ResetCache(pPage, nullptr);
}
pImgObj->m_pImage->SetJpegImage(pFile);
@@ -54,13 +53,14 @@
double f) {
if (!image_object)
return FALSE;
- CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
- pImgObj->m_Matrix.a = (FX_FLOAT)a;
- pImgObj->m_Matrix.b = (FX_FLOAT)b;
- pImgObj->m_Matrix.c = (FX_FLOAT)c;
- pImgObj->m_Matrix.d = (FX_FLOAT)d;
- pImgObj->m_Matrix.e = (FX_FLOAT)e;
- pImgObj->m_Matrix.f = (FX_FLOAT)f;
+
+ CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
+ pImgObj->m_Matrix.a = static_cast<FX_FLOAT>(a);
+ pImgObj->m_Matrix.b = static_cast<FX_FLOAT>(b);
+ pImgObj->m_Matrix.c = static_cast<FX_FLOAT>(c);
+ pImgObj->m_Matrix.d = static_cast<FX_FLOAT>(d);
+ pImgObj->m_Matrix.e = static_cast<FX_FLOAT>(e);
+ pImgObj->m_Matrix.f = static_cast<FX_FLOAT>(f);
pImgObj->CalcBoundingBox();
return TRUE;
}
@@ -71,17 +71,15 @@
FPDF_BITMAP bitmap) {
if (!image_object || !bitmap || !pages)
return FALSE;
- CFX_DIBitmap* pBmp = nullptr;
- pBmp = (CFX_DIBitmap*)bitmap;
- CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+
+ CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
pImgObj->m_GeneralState.GetModify();
for (int index = 0; index < nCount; index++) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
- if (!pPage)
- continue;
- pImgObj->m_pImage->ResetCache(pPage, nullptr);
+ if (pPage)
+ pImgObj->m_pImage->ResetCache(pPage, nullptr);
}
- pImgObj->m_pImage->SetImage(pBmp, FALSE);
+ pImgObj->m_pImage->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap), FALSE);
pImgObj->CalcBoundingBox();
return TRUE;
}