diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-05-19 14:48:00 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-05-19 14:48:00 -0700 |
commit | eb6527763171cdb4b0fbfea5a20d691f4d67b660 (patch) | |
tree | 7781d0fb716b95696b9f411037508244f4cfc28a /core/src/fpdfapi | |
parent | 59f4b44d1fbb259967ea518e0bf5fa76b0cc9767 (diff) | |
download | pdfium-eb6527763171cdb4b0fbfea5a20d691f4d67b660.tar.xz |
Remove FX_Alloc() null checks now that it can't return NULL.
This permits some functions to become void's since
they, in turn, can't fail.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1142713005
Diffstat (limited to 'core/src/fpdfapi')
8 files changed, 11 insertions, 40 deletions
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index 0886d3ff53..3abbcee046 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -415,9 +415,6 @@ FX_BOOL CPDF_Encryptor::Initialize(CPDF_CryptoHandler* pHandler, int objnum, FX_ } m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size); m_pData = FX_Alloc(FX_BYTE, m_dwSize); - if(!m_pData) { - return FALSE; - } pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); m_bNewBuf = TRUE; return TRUE; diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp index 1328fcdf96..a5a91ebc53 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); } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index 4ec753d751..5a9f1a8cb8 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -204,11 +204,10 @@ void CPDF_TextObject::CopyData(const CPDF_PageObject* pSrc) if (m_nChars > 1) { m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); - int i; - for (i = 0; i < m_nChars; i ++) { + for (int i = 0; i < m_nChars; i ++) { m_pCharCodes[i] = pSrcObj->m_pCharCodes[i]; } - for (i = 0; i < m_nChars - 1; i ++) { + for (int i = 0; i < m_nChars - 1; i ++) { m_pCharPos[i] = pSrcObj->m_pCharPos[i]; } } else { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 952fe1d9a9..d8b24593ef 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -262,8 +262,8 @@ FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, FX_LPBYTE& dest_b delete pDecoder; return -1; } - dest_size = pitch * height; - dest_buf = FX_Alloc( FX_BYTE, dest_size); + dest_buf = FX_Alloc2D(FX_BYTE, pitch, height); + dest_size = pitch * height; // Safe since checked alloc returned. for (int row = 0; row < height; row ++) { FX_LPBYTE pLine = pDecoder->GetScanline(row); if (pLine == NULL) { @@ -1050,10 +1050,6 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) m_Size += size + 1; } m_pData = FX_Alloc(FX_BYTE, m_Size); - if (!m_pData) { - m_Status = Done; - return; - } FX_DWORD pos = 0; for (i = 0; i < m_nStreams; i ++) { FXSYS_memcpy32(m_pData + pos, m_pStreamArray[i]->GetData(), m_pStreamArray[i]->GetSize()); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 8f5871df7f..691981cb10 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -40,9 +40,6 @@ FX_DWORD _A85Decode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_b return (FX_DWORD) - 1; } dest_buf = FX_Alloc(FX_BYTE, zcount * 4 + (pos - zcount)); - if (dest_buf == NULL) { - return (FX_DWORD) - 1; - } int state = 0; FX_UINT32 res = 0; pos = dest_size = 0; @@ -153,9 +150,6 @@ FX_DWORD RunLengthDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& d return -1; } dest_buf = FX_Alloc( FX_BYTE, dest_size); - if (!dest_buf) { - return -1; - } i = 0; int dest_count = 0; while (i < src_size) { diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 3eac5ae74e..341be13d44 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -1086,7 +1086,7 @@ void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, FX_BOOL bRawAccess, } if (!pStream->IsMemoryBased()) { pSrcData = m_pSrcData = FX_Alloc(FX_BYTE, dwSrcSize); - if (!pSrcData || !pStream->ReadRawData(0, pSrcData, dwSrcSize)) { + if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) { return; } } else { @@ -1165,9 +1165,6 @@ FX_LPBYTE CPDF_StreamAcc::DetachData() return p; } FX_LPBYTE p = FX_Alloc(FX_BYTE, m_dwSize); - if (p == NULL) { - return NULL; - } FXSYS_memcpy32(p, m_pData, m_dwSize); return p; } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 2772d9825e..0d4ed27c06 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2477,9 +2477,6 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT } CPDF_Stream* pStream; FX_LPBYTE pData = FX_Alloc(FX_BYTE, len); - if (!pData) { - return NULL; - } ReadBlock(pData, len); if (pCryptoHandler) { CFX_BinaryBuf dest_buf; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 7093edae47..b45d9c3e5d 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -500,9 +500,6 @@ DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, FX return NULL; } DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); - if (pCompData == NULL) { - return NULL; - } int max_data = (1 << m_bpc) - 1; CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); if (pDecode) { |