diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-10-09 19:04:04 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-09 19:04:04 +0000 |
commit | 1fc902fef97883f91a1ccf5bb3333ef11ed3b8fd (patch) | |
tree | abe87980b363db2ac1efa0e0ff638f4b0b70b42f | |
parent | 7fb895f623e607a3c3b26b2caca0b15a0ef6947c (diff) | |
download | pdfium-1fc902fef97883f91a1ccf5bb3333ef11ed3b8fd.tar.xz |
Kill off some memset()s following FX_Alloc()
Change-Id: I92aa74c86aef890fcb991f039b9707d680fdb83c
Reviewed-on: https://pdfium-review.googlesource.com/c/43652
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fxcodec/codec/ccodec_progressivedecoder.cpp | 6 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fx_memory.h | 4 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_ErrorCorrection.cpp | 1 |
4 files changed, 2 insertions, 13 deletions
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.cpp b/core/fxcodec/codec/ccodec_progressivedecoder.cpp index 27a2494baf..0e6014595e 100644 --- a/core/fxcodec/codec/ccodec_progressivedecoder.cpp +++ b/core/fxcodec/codec/ccodec_progressivedecoder.cpp @@ -805,7 +805,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::BmpStartDecode( GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); m_ScanlineSize = FxAlignToBoundary<4>(m_SrcWidth * m_SrcComponents); m_pDecodeBuf.reset(FX_Alloc(uint8_t, m_ScanlineSize)); - memset(m_pDecodeBuf.get(), 0, m_ScanlineSize); m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, m_clipBox.Width()); m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); @@ -903,7 +902,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GifStartDecode( GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); int scanline_size = FxAlignToBoundary<4>(m_SrcWidth); m_pDecodeBuf.reset(FX_Alloc(uint8_t, scanline_size)); - memset(m_pDecodeBuf.get(), 0, scanline_size); m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, m_clipBox.Width()); m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); @@ -1110,7 +1108,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::JpegStartDecode( int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale; scanline_size = FxAlignToBoundary<4>(scanline_size * m_SrcComponents); m_pDecodeBuf.reset(FX_Alloc(uint8_t, scanline_size)); - memset(m_pDecodeBuf.get(), 0, scanline_size); m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, m_clipBox.Width()); m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); @@ -1272,7 +1269,6 @@ bool CCodec_ProgressiveDecoder::PngDetectImageTypeInBuffer( } if (m_pSrcBuf && input_size > m_SrcSize) { m_pSrcBuf.reset(FX_Alloc(uint8_t, input_size)); - memset(m_pSrcBuf.get(), 0, input_size); m_SrcSize = input_size; } bResult = m_pFile->ReadBlock(m_pSrcBuf.get(), m_offSet, input_size); @@ -1334,7 +1330,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::PngStartDecode( GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); int scanline_size = FxAlignToBoundary<4>(m_SrcWidth * m_SrcComponents); m_pDecodeBuf.reset(FX_Alloc(uint8_t, scanline_size)); - memset(m_pDecodeBuf.get(), 0, scanline_size); m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width()); m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; @@ -1360,7 +1355,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::PngContinueDecode() { } if (m_pSrcBuf && input_size > m_SrcSize) { m_pSrcBuf.reset(FX_Alloc(uint8_t, input_size)); - memset(m_pSrcBuf.get(), 0, input_size); m_SrcSize = input_size; } bool bResult = m_pFile->ReadBlock(m_pSrcBuf.get(), m_offSet, input_size); diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 4656bfa084..3a868c1486 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -817,7 +817,6 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) { if (pTRD->SBREFINE == 1) { const size_t size = GetRefAggContextSize(pTRD->SBRTEMPLATE); grContext.reset(FX_Alloc(JBig2ArithCtx, size)); - memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); } if (pTRD->SBHUFF == 0) { auto pArithDecoder = @@ -871,7 +870,6 @@ JBig2_Result CJBig2_Context::ParsePatternDict(CJBig2_Segment* pSegment, const size_t size = GetHuffContextSize(pPDD->HDTEMPLATE); std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( FX_Alloc(JBig2ArithCtx, size)); - memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_PatternDict = @@ -940,7 +938,6 @@ JBig2_Result CJBig2_Context::ParseHalftoneRegion(CJBig2_Segment* pSegment, const size_t size = GetHuffContextSize(pHRD->HTEMPLATE); std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( FX_Alloc(JBig2ArithCtx, size)); - memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_Image = @@ -1123,7 +1120,6 @@ JBig2_Result CJBig2_Context::ParseGenericRefinementRegion( const size_t size = GetRefAggContextSize(pGRRD->GRTEMPLATE); std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext( FX_Alloc(JBig2ArithCtx, size)); - memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; pSegment->m_Image = pGRRD->Decode(pArithDecoder.get(), grContext.get()); diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index b39911269b..5596bceabe 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -88,7 +88,7 @@ inline void* FX_ReallocOrDie(void* ptr, return result; } -// These never return nullptr. +// These never return nullptr, and must return cleared memory. #define FX_Alloc(type, size) \ static_cast<type*>(FX_AllocOrDie(size, sizeof(type))) #define FX_Alloc2D(type, w, h) \ @@ -96,7 +96,7 @@ inline void* FX_ReallocOrDie(void* ptr, #define FX_Realloc(type, ptr, size) \ static_cast<type*>(FX_ReallocOrDie(ptr, size, sizeof(type))) -// May return nullptr. +// May return nullptr, but returns cleared memory otherwise. #define FX_TryAlloc(type, size) \ static_cast<type*>(FX_SafeAlloc(size, sizeof(type))) #define FX_TryRealloc(type, ptr, size) \ diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp index 83442645e4..87dc5f6e47 100644 --- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -184,7 +184,6 @@ WideString CBC_ErrorCorrection::createECCBlock(WideString codewords, return WideString(); } uint16_t* ecc = FX_Alloc(uint16_t, numECWords); - memset(ecc, 0, numECWords * sizeof(uint16_t)); for (int32_t l = start; l < start + len; l++) { uint16_t m = ecc[numECWords - 1] ^ codewords[l]; for (int32_t k = numECWords - 1; k > 0; k--) { |