summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-16 16:54:02 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-16 16:54:02 +0000
commit481749905d444745ee0ba76d9bcf42b3b009bb27 (patch)
tree630037bdc9e9d03bcc0382da3e6718bf0456c0aa
parentbfeb9343ee794a48b70c2f638c3d74f96e9afab2 (diff)
downloadpdfium-chromium/3494.tar.xz
Get rid of some loose allocs/free in CPDF_Document.chromium/3494
Use std::vector<> as a manager for contiguous buffers. Change-Id: Icaacbd4b7010b928237aa71485411ade7539412a Reviewed-on: https://pdfium-review.googlesource.com/37012 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp39
1 files changed, 18 insertions, 21 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 4f699139a3..311e017148 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -39,30 +39,29 @@ namespace {
const int FX_MAX_PAGE_LEVEL = 1024;
-void InsertWidthArrayImpl(int* widths, int size, CPDF_Array* pWidthArray) {
- int i;
- for (i = 1; i < size; i++) {
- if (widths[i] != *widths)
+void InsertWidthArrayImpl(std::vector<int> widths, CPDF_Array* pWidthArray) {
+ size_t i;
+ for (i = 1; i < widths.size(); i++) {
+ if (widths[i] != widths[0])
break;
}
- if (i == size) {
+ if (i == widths.size()) {
int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1);
- pWidthArray->AddNew<CPDF_Number>(first + size - 1);
- pWidthArray->AddNew<CPDF_Number>(*widths);
- } else {
- CPDF_Array* pWidthArray1 = pWidthArray->AddNew<CPDF_Array>();
- for (i = 0; i < size; i++)
- pWidthArray1->AddNew<CPDF_Number>(widths[i]);
+ pWidthArray->AddNew<CPDF_Number>(first + static_cast<int>(widths.size()) -
+ 1);
+ pWidthArray->AddNew<CPDF_Number>(widths[0]);
+ return;
}
- FX_Free(widths);
+ CPDF_Array* pWidthArray1 = pWidthArray->AddNew<CPDF_Array>();
+ for (int w : widths)
+ pWidthArray1->AddNew<CPDF_Number>(w);
}
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
void InsertWidthArray(HDC hDC, int start, int end, CPDF_Array* pWidthArray) {
- int size = end - start + 1;
- int* widths = FX_Alloc(int, size);
- GetCharWidth(hDC, start, end, widths);
- InsertWidthArrayImpl(widths, size, pWidthArray);
+ std::vector<int> widths(end - start + 1);
+ GetCharWidth(hDC, start, end, widths.data());
+ InsertWidthArrayImpl(std::move(widths), pWidthArray);
}
ByteString FPDF_GetPSNameFromTT(HDC hDC) {
@@ -83,14 +82,12 @@ void InsertWidthArray1(CFX_Font* pFont,
wchar_t start,
wchar_t end,
CPDF_Array* pWidthArray) {
- int size = end - start + 1;
- int* widths = FX_Alloc(int, size);
- int i;
- for (i = 0; i < size; i++) {
+ std::vector<int> widths(end - start + 1);
+ for (size_t i = 0; i < widths.size(); ++i) {
int glyph_index = pEncoding->GlyphFromCharCode(start + i);
widths[i] = pFont->GetGlyphWidth(glyph_index);
}
- InsertWidthArrayImpl(widths, size, pWidthArray);
+ InsertWidthArrayImpl(std::move(widths), pWidthArray);
}
int CountPages(CPDF_Dictionary* pPages,