Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp

Issue 1142713005: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix missing FX_Alloc2D, check overflow on add, remove unused enum. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
index 1328fcdf96a4d9a0401b7bff9ee33ab0ac6cd968..a5a91ebc53ba719e09d0a6705c601a5aa9acfced 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
@@ -71,17 +71,11 @@ void CPDF_Image::SetJpegImage(IFX_FileRead *pFile)
dwEstimateSize = 8192;
}
FX_LPBYTE pData = FX_Alloc(FX_BYTE, dwEstimateSize);
- if (!pData) {
- return;
- }
pFile->ReadBlock(pData, 0, dwEstimateSize);
CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize);
FX_Free(pData);
if (!pDict && size > dwEstimateSize) {
pData = FX_Alloc(FX_BYTE, size);
- if (!pData) {
- return;
- }
pFile->ReadBlock(pData, 0, size);
pDict = InitJPEG(pData, size);
FX_Free(pData);
@@ -223,8 +217,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F
} else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
_JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, mask_size, TRUE);
} else {
- mask_size = maskHeight * maskWidth;
- mask_buf = FX_Alloc(FX_BYTE, mask_size);
+ mask_buf = FX_Alloc2D(FX_BYTE, maskHeight, maskWidth);
+ mask_size = maskHeight * maskWidth; // Safe since checked alloc returned.
for (FX_INT32 a = 0; a < maskHeight; a ++) {
FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), maskWidth);
}
@@ -306,8 +300,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F
}
} else if (opType == 1) {
if (!bStream) {
- dest_size = dest_pitch * BitmapHeight;
- dest_buf = FX_Alloc(FX_BYTE, dest_size);
+ dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight);
+ dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned.
}
FX_LPBYTE pDest = dest_buf;
for (FX_INT32 i = 0; i < BitmapHeight; i ++) {
@@ -321,8 +315,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F
}
} else if (opType == 2) {
if (!bStream) {
- dest_size = dest_pitch * BitmapHeight;
- dest_buf = FX_Alloc(FX_BYTE, dest_size);
+ dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight);
+ dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned.
} else {
dest_buf = FX_Alloc(FX_BYTE, dest_pitch);
}
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698