From c05ddc26a1e9c150d8f6ce60b08ea0b595143d9d Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 1 Jun 2018 18:02:24 +0000 Subject: Clean up some issues found in CXFA_TextLayout Initialize pCharPos to non-NULL, so that later code can depend on it != nullptr, avoiding a potential call to memset on nullptr. Additionally get rid of a free then alloc pattern and just use realloc. Later on remove updates to fBaseLineTemp that have not effect, since it isn't read after them. Issues found with Clang Static Analyzer. Change-Id: Iff175e20cd8860d263a56a24c8781e214c61d02c Reviewed-on: https://pdfium-review.googlesource.com/33533 Reviewed-by: Henrique Nakashima Commit-Queue: Ryan Harrison --- xfa/fxfa/cxfa_textlayout.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index 749ce2d3f9..c0f786bbcf 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -560,8 +560,8 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, Layout(i); } - FXTEXT_CHARPOS* pCharPos = nullptr; - int32_t iCharCount = 0; + FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, 1); + int32_t iCharCount = 1; int32_t iLineStart = 0; int32_t iPieceLines = pdfium::CollectionSize(m_pieceLines); int32_t iCount = pdfium::CollectionSize(m_Blocks); @@ -586,8 +586,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[j].get(); int32_t iChars = pPiece->iChars; if (iCharCount < iChars) { - FX_Free(pCharPos); - pCharPos = FX_Alloc(FXTEXT_CHARPOS, iChars); + pCharPos = FX_Realloc(FXTEXT_CHARPOS, pCharPos, iChars); iCharCount = iChars; } memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); @@ -1045,10 +1044,6 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, float fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; if (fLineHeight < fLineHeightTmp) fLineHeight = fLineHeightTmp; - else - fBaseLineTemp = 0; - } else if (fBaseLine < -fBaseLineTemp) { - fBaseLine = -fBaseLineTemp; } fLineStep = std::max(fLineStep, fLineHeight); pTP->pLinkData = pUserData ? pUserData->m_pLinkData : nullptr; -- cgit v1.2.3