diff options
author | Lei Zhang <thestig@chromium.org> | 2016-02-22 20:32:21 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-02-22 20:32:21 -0800 |
commit | 5eca305b1586b2107566a5c124baa5f2e00096c0 (patch) | |
tree | d2b6b17b62995b2249a28956a17ae87122f83124 /core/src/fxcodec/codec | |
parent | d2019df0a77c5d01a336f16be054d2f373e38c54 (diff) | |
download | pdfium-5eca305b1586b2107566a5c124baa5f2e00096c0.tar.xz |
Remove foo != NULL outside of xfa/
Most of these are from the XFA branch.
R=dsinclair@chromium.org
Review URL: https://codereview.chromium.org/1720043003 .
Diffstat (limited to 'core/src/fxcodec/codec')
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_bmp.cpp | 6 | ||||
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_gif.cpp | 6 | ||||
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_png.cpp | 10 | ||||
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_progress.cpp | 131 | ||||
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_progress.h | 18 |
5 files changed, 47 insertions, 124 deletions
diff --git a/core/src/fxcodec/codec/fx_codec_bmp.cpp b/core/src/fxcodec/codec/fx_codec_bmp.cpp index 4e5fef0d1d..042392c0d1 100644 --- a/core/src/fxcodec/codec/fx_codec_bmp.cpp +++ b/core/src/fxcodec/codec/fx_codec_bmp.cpp @@ -21,9 +21,7 @@ static void* _bmp_alloc_func(unsigned int size) { return FX_Alloc(char, size); } static void _bmp_free_func(void* p) { - if (p != NULL) { - FX_Free(p); - } + FX_Free(p); } }; static void _bmp_error_data(bmp_decompress_struct_p bmp_ptr, @@ -72,7 +70,7 @@ void* CCodec_BmpModule::Start(void* pModule) { } void CCodec_BmpModule::Finish(void* pContext) { FXBMP_Context* p = (FXBMP_Context*)pContext; - if (p != NULL) { + if (p) { _bmp_destroy_decompress(&p->bmp_ptr); p->m_FreeFunc(p); } diff --git a/core/src/fxcodec/codec/fx_codec_gif.cpp b/core/src/fxcodec/codec/fx_codec_gif.cpp index 4c60a0392c..af0c32ea9d 100644 --- a/core/src/fxcodec/codec/fx_codec_gif.cpp +++ b/core/src/fxcodec/codec/fx_codec_gif.cpp @@ -21,9 +21,7 @@ static void* _gif_alloc_func(unsigned int size) { return FX_Alloc(char, size); } static void _gif_free_func(void* p) { - if (p != NULL) { - FX_Free(p); - } + FX_Free(p); } }; static void _gif_error_data(gif_decompress_struct_p gif_ptr, @@ -98,7 +96,7 @@ void* CCodec_GifModule::Start(void* pModule) { } void CCodec_GifModule::Finish(void* pContext) { FXGIF_Context* p = (FXGIF_Context*)pContext; - if (p != NULL) { + if (p) { _gif_destroy_decompress(&p->gif_ptr); p->m_FreeFunc(p); } diff --git a/core/src/fxcodec/codec/fx_codec_png.cpp b/core/src/fxcodec/codec/fx_codec_png.cpp index 0df3455522..c8cb1b8a6a 100644 --- a/core/src/fxcodec/codec/fx_codec_png.cpp +++ b/core/src/fxcodec/codec/fx_codec_png.cpp @@ -105,9 +105,7 @@ static void* _png_alloc_func(unsigned int size) { return FX_Alloc(char, size); } static void _png_free_func(void* p) { - if (p != NULL) { - FX_Free(p); - } + FX_Free(p); } }; static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { @@ -192,7 +190,7 @@ static void _png_get_row_func(png_structp png_ptr, if (!pModule->AskScanlineBufCallback(p->child_ptr, row_num, src_buf)) { png_error(png_ptr, "Ask Scanline buffer Callback Error"); } - if (src_buf != NULL) { + if (src_buf) { png_progressive_combine_row(png_ptr, src_buf, new_row); } pModule->FillScanlineBufCompletedCallback(p->child_ptr, pass, row_num); @@ -220,7 +218,7 @@ void* CCodec_PngModule::Start(void* pModule) { return NULL; } if (setjmp(png_jmpbuf(p->png_ptr))) { - if (p != NULL) { + if (p) { png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL); FX_Free(p); } @@ -234,7 +232,7 @@ void* CCodec_PngModule::Start(void* pModule) { } void CCodec_PngModule::Finish(void* pContext) { FXPNG_Context* p = (FXPNG_Context*)pContext; - if (p != NULL) { + if (p) { png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL); p->m_FreeFunc(p); } diff --git a/core/src/fxcodec/codec/fx_codec_progress.cpp b/core/src/fxcodec/codec/fx_codec_progress.cpp index 2edf750d7f..2e9b1dce3e 100644 --- a/core/src/fxcodec/codec/fx_codec_progress.cpp +++ b/core/src/fxcodec/codec/fx_codec_progress.cpp @@ -272,30 +272,24 @@ CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder( } CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() { m_pFile = NULL; - if (m_pJpegContext != NULL) { + if (m_pJpegContext) { m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext); } - if (m_pPngContext != NULL) { + if (m_pPngContext) { m_pCodecMgr->GetPngModule()->Finish(m_pPngContext); } - if (m_pGifContext != NULL) { + if (m_pGifContext) { m_pCodecMgr->GetGifModule()->Finish(m_pGifContext); } - if (m_pBmpContext != NULL) { + if (m_pBmpContext) { m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext); } - if (m_pTiffContext != NULL) { + if (m_pTiffContext) { m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext); } - if (m_pSrcBuf != NULL) { - FX_Free(m_pSrcBuf); - } - if (m_pDecodeBuf != NULL) { - FX_Free(m_pDecodeBuf); - } - if (m_pSrcPalette != NULL) { - FX_Free(m_pSrcPalette); - } + FX_Free(m_pSrcBuf); + FX_Free(m_pDecodeBuf); + FX_Free(m_pSrcPalette); } FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData( ICodec_JpegModule* pJpegModule, @@ -387,8 +381,8 @@ FX_BOOL CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule, uint8_t*& src_buf) { CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; - ASSERT(pDIBitmap != NULL); - if (pDIBitmap == NULL) { + if (!pDIBitmap) { + ASSERT(false); return FALSE; } if (line >= pCodec->m_clipBox.top && line < pCodec->m_clipBox.bottom) { @@ -418,7 +412,7 @@ FX_BOOL CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule, return FALSE; case FXDIB_8bppMask: case FXDIB_8bppRgb: { - if (pDIBitmap->GetPalette() != NULL) { + if (pDIBitmap->GetPalette()) { return FALSE; } FX_DWORD des_g = 0; @@ -477,7 +471,7 @@ void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz( return; case FXDIB_8bppMask: case FXDIB_8bppRgb: { - if (pDeviceBitmap->GetPalette() != NULL) { + if (pDeviceBitmap->GetPalette()) { return; } FX_DWORD des_g = 0; @@ -532,7 +526,7 @@ void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule, int line) { CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; - ASSERT(pDIBitmap != NULL); + ASSERT(pDIBitmap); int src_top = pCodec->m_clipBox.top; int src_bottom = pCodec->m_clipBox.bottom; int des_top = pCodec->m_startY; @@ -700,7 +694,7 @@ void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule, uint8_t* row_buf) { CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; - ASSERT(pDIBitmap != NULL); + ASSERT(pDIBitmap); int32_t img_width = pCodec->m_GifFrameRect.Width(); if (!pDIBitmap->HasAlpha()) { uint8_t* byte_ptr = row_buf; @@ -788,7 +782,7 @@ void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert( return; case FXDIB_8bppMask: case FXDIB_8bppRgb: { - if (pDeviceBitmap->GetPalette() != NULL) { + if (pDeviceBitmap->GetPalette()) { return; } int des_g = 0; @@ -891,7 +885,7 @@ void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule, uint8_t* row_buf) { CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; - ASSERT(pDIBitmap != NULL); + ASSERT(pDIBitmap); FXSYS_memcpy(pCodec->m_pDecodeBuf, row_buf, pCodec->m_ScanlineSize); int src_top = pCodec->m_clipBox.top; int src_bottom = pCodec->m_clipBox.bottom; @@ -953,7 +947,7 @@ void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, return; case FXDIB_8bppMask: case FXDIB_8bppRgb: { - if (pDeviceBitmap->GetPalette() != NULL) { + if (pDeviceBitmap->GetPalette()) { return; } int des_g = 0; @@ -1006,15 +1000,8 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( if (size > FXCODEC_BLOCK_SIZE) { size = FXCODEC_BLOCK_SIZE; } - if (m_pSrcBuf != NULL) { - FX_Free(m_pSrcBuf); - m_pSrcBuf = NULL; - } + FX_Free(m_pSrcBuf); m_pSrcBuf = FX_Alloc(uint8_t, size); - if (m_pSrcBuf == NULL) { - m_status = FXCODEC_STATUS_ERR_MEMORY; - return FALSE; - } FXSYS_memset(m_pSrcBuf, 0, size); m_SrcSize = size; switch (imageType) { @@ -1056,22 +1043,17 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( if (readResult == 1) { m_SrcBPC = 8; m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); - if (m_pSrcPalette != NULL) { - FX_Free(m_pSrcPalette); - m_pSrcPalette = NULL; - } + FX_Free(m_pSrcPalette); if (m_SrcPaletteNumber) { m_pSrcPalette = FX_Alloc(FX_ARGB, m_SrcPaletteNumber); - if (m_pSrcPalette == NULL) { - m_status = FXCODEC_STATUS_ERR_MEMORY; - return FALSE; - } FXSYS_memcpy(m_pSrcPalette, pPalette, m_SrcPaletteNumber * sizeof(FX_DWORD)); + } else { + m_pSrcPalette = nullptr; } return TRUE; } - if (m_pBmpContext != NULL) { + if (m_pBmpContext) { pBmpModule->Finish(m_pBmpContext); m_pBmpContext = NULL; } @@ -1114,7 +1096,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); return TRUE; } - if (m_pJpegContext != NULL) { + if (m_pJpegContext) { pJpegModule->Finish(m_pJpegContext); m_pJpegContext = NULL; } @@ -1150,20 +1132,16 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( FX_DWORD input_size = remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; if (input_size == 0) { - if (m_pPngContext != NULL) { + if (m_pPngContext) { pPngModule->Finish(m_pPngContext); } m_pPngContext = NULL; m_status = FXCODEC_STATUS_ERR_FORMAT; return FALSE; } - if (m_pSrcBuf != NULL && input_size > m_SrcSize) { + if (m_pSrcBuf && input_size > m_SrcSize) { FX_Free(m_pSrcBuf); m_pSrcBuf = FX_Alloc(uint8_t, input_size); - if (m_pSrcBuf == NULL) { - m_status = FXCODEC_STATUS_ERR_MEMORY; - return FALSE; - } FXSYS_memset(m_pSrcBuf, 0, input_size); m_SrcSize = input_size; } @@ -1177,7 +1155,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, pAttribute); } ASSERT(!bResult); - if (m_pPngContext != NULL) { + if (m_pPngContext) { pPngModule->Finish(m_pPngContext); m_pPngContext = NULL; } @@ -1231,7 +1209,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); return TRUE; } - if (m_pGifContext != NULL) { + if (m_pGifContext) { pGifModule->Finish(m_pGifContext); m_pGifContext = NULL; } @@ -1711,7 +1689,7 @@ void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, return; case FXDIB_8bppMask: case FXDIB_8bppRgb: { - if (pDeviceBitmap->GetPalette() != NULL) { + if (pDeviceBitmap->GetPalette()) { return; } int des_g = 0; @@ -1836,7 +1814,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames, frames = m_FrameNumber; return m_status = FXCODEC_STATUS_DECODE_READY; } - if (m_pGifContext != NULL) { + if (m_pGifContext) { pGifModule->Finish(m_pGifContext); m_pGifContext = NULL; } @@ -1921,16 +1899,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, } int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale; scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4; - if (m_pDecodeBuf != NULL) { - FX_Free(m_pDecodeBuf); - m_pDecodeBuf = NULL; - } + FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); - if (m_pDecodeBuf == NULL) { - m_pDeviceBitmap = NULL; - m_pFile = NULL; - return m_status = FXCODEC_STATUS_ERR_MEMORY; - } FXSYS_memset(m_pDecodeBuf, 0, scanline_size); m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, m_clipBox.Width(), m_bInterpol); @@ -1956,7 +1926,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_pFile = NULL; return m_status = FXCODEC_STATUS_ERR_MEMORY; } - if (m_pPngContext != NULL) { + if (m_pPngContext) { pPngModule->Finish(m_pPngContext); m_pPngContext = NULL; } @@ -1990,16 +1960,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, } GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; - if (m_pDecodeBuf != NULL) { - FX_Free(m_pDecodeBuf); - m_pDecodeBuf = NULL; - } + FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); - if (m_pDecodeBuf == NULL) { - m_pDeviceBitmap = NULL; - m_pFile = NULL; - return m_status = FXCODEC_STATUS_ERR_MEMORY; - } FXSYS_memset(m_pDecodeBuf, 0, scanline_size); m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol); m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); @@ -2015,16 +1977,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_SrcFormat = FXCodec_8bppRgb; GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); int scanline_size = (m_SrcWidth + 3) / 4 * 4; - if (m_pDecodeBuf != NULL) { - FX_Free(m_pDecodeBuf); - m_pDecodeBuf = NULL; - } + FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); - if (m_pDecodeBuf == NULL) { - m_pDeviceBitmap = NULL; - m_pFile = NULL; - return m_status = FXCODEC_STATUS_ERR_MEMORY; - } FXSYS_memset(m_pDecodeBuf, 0, scanline_size); m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, m_clipBox.Width(), m_bInterpol); @@ -2052,16 +2006,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, } GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; - if (m_pDecodeBuf != NULL) { - FX_Free(m_pDecodeBuf); - m_pDecodeBuf = NULL; - } + FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, m_ScanlineSize); - if (m_pDecodeBuf == NULL) { - m_pDeviceBitmap = NULL; - m_pFile = NULL; - return m_status = FXCODEC_STATUS_ERR_MEMORY; - } FXSYS_memset(m_pDecodeBuf, 0, m_ScanlineSize); m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, m_clipBox.Width(), m_bInterpol); @@ -2117,7 +2063,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { FX_DWORD input_size = remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; if (input_size == 0) { - if (m_pPngContext != NULL) { + if (m_pPngContext) { pPngModule->Finish(m_pPngContext); } m_pPngContext = NULL; @@ -2125,14 +2071,9 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { m_pFile = NULL; return m_status = FXCODEC_STATUS_DECODE_FINISH; } - if (m_pSrcBuf != NULL && input_size > m_SrcSize) { + if (m_pSrcBuf && input_size > m_SrcSize) { FX_Free(m_pSrcBuf); m_pSrcBuf = FX_Alloc(uint8_t, input_size); - if (m_pSrcBuf == NULL) { - m_pDeviceBitmap = NULL; - m_pFile = NULL; - return m_status = FXCODEC_STATUS_ERR_MEMORY; - } FXSYS_memset(m_pSrcBuf, 0, input_size); m_SrcSize = input_size; } diff --git a/core/src/fxcodec/codec/fx_codec_progress.h b/core/src/fxcodec/codec/fx_codec_progress.h index 45fde21338..4fb13640ff 100644 --- a/core/src/fxcodec/codec/fx_codec_progress.h +++ b/core/src/fxcodec/codec/fx_codec_progress.h @@ -21,11 +21,7 @@ struct PixelWeight { class CFXCODEC_WeightTable { public: CFXCODEC_WeightTable() { m_pWeightTables = NULL; } - ~CFXCODEC_WeightTable() { - if (m_pWeightTables != NULL) { - FX_Free(m_pWeightTables); - } - } + ~CFXCODEC_WeightTable() { FX_Free(m_pWeightTables); } void Calc(int dest_len, int dest_min, @@ -44,11 +40,7 @@ class CFXCODEC_WeightTable { class CFXCODEC_HorzTable { public: CFXCODEC_HorzTable() { m_pWeightTables = NULL; } - ~CFXCODEC_HorzTable() { - if (m_pWeightTables != NULL) { - FX_Free(m_pWeightTables); - } - } + ~CFXCODEC_HorzTable() { FX_Free(m_pWeightTables); } void Calc(int dest_len, int src_len, FX_BOOL bInterpol); PixelWeight* GetPixelWeight(int pixel) { @@ -61,11 +53,7 @@ class CFXCODEC_HorzTable { class CFXCODEC_VertTable { public: CFXCODEC_VertTable() { m_pWeightTables = NULL; } - ~CFXCODEC_VertTable() { - if (m_pWeightTables != NULL) { - FX_Free(m_pWeightTables); - } - } + ~CFXCODEC_VertTable() { FX_Free(m_pWeightTables); } void Calc(int dest_len, int src_len); PixelWeight* GetPixelWeight(int pixel) { return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize); |