Use a vector inside CPDF_CharPosList. Change-Id: I3f83e9f94e3c6802d453057b6b5bff91dc5afa76 Reviewed-on: https://pdfium-review.googlesource.com/c/50076 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp index b59564d..8603531 100644 --- a/core/fpdfapi/render/cpdf_charposlist.cpp +++ b/core/fpdfapi/render/cpdf_charposlist.cpp
@@ -15,17 +15,17 @@ const std::vector<float>& charPos, CPDF_Font* pFont, float FontSize) { - m_pCharPos = FX_Alloc(TextCharPos, charCodes.size()); - m_nChars = 0; + m_CharPos.reserve(charCodes.size()); CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); bool bVertWriting = pCIDFont && pCIDFont->IsVertWriting(); - for (size_t iChar = 0; iChar < charCodes.size(); ++iChar) { - uint32_t CharCode = charCodes[iChar]; + for (size_t i = 0; i < charCodes.size(); ++i) { + uint32_t CharCode = charCodes[i]; if (CharCode == static_cast<uint32_t>(-1)) continue; bool bVert = false; - TextCharPos& charpos = m_pCharPos[m_nChars++]; + m_CharPos.emplace_back(); + TextCharPos& charpos = m_CharPos.back(); if (pCIDFont) charpos.m_bFontStyle = true; WideString unicode = pFont->UnicodeFromCharCode(CharCode); @@ -58,7 +58,7 @@ else charpos.m_FontCharWidth = 0; - charpos.m_Origin = CFX_PointF(iChar > 0 ? charPos[iChar - 1] : 0, 0); + charpos.m_Origin = CFX_PointF(i > 0 ? charPos[i - 1] : 0, 0); charpos.m_bGlyphAdjust = false; float scalingFactor = 1.0f; @@ -113,14 +113,12 @@ } } -CPDF_CharPosList::~CPDF_CharPosList() { - FX_Free(m_pCharPos); -} +CPDF_CharPosList::~CPDF_CharPosList() = default; uint32_t CPDF_CharPosList::GetCount() const { - return m_nChars; + return pdfium::CollectionSize<uint32_t>(m_CharPos); } const TextCharPos& CPDF_CharPosList::GetAt(size_t index) const { - return m_pCharPos[index]; + return m_CharPos[index]; }
diff --git a/core/fpdfapi/render/cpdf_charposlist.h b/core/fpdfapi/render/cpdf_charposlist.h index a8872a0..9635f1b 100644 --- a/core/fpdfapi/render/cpdf_charposlist.h +++ b/core/fpdfapi/render/cpdf_charposlist.h
@@ -22,14 +22,12 @@ float font_size); ~CPDF_CharPosList(); - uint32_t empty() const { return m_nChars == 0; } + uint32_t empty() const { return m_CharPos.empty(); } uint32_t GetCount() const; const TextCharPos& GetAt(size_t index) const; private: - // TODO(thestig): Convert to unique_ptr or vector. - TextCharPos* m_pCharPos = nullptr; - uint32_t m_nChars = 0; + std::vector<TextCharPos> m_CharPos; }; #endif // CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_