From 822484b5f88d92dbcd567b1c2da38af1e720b56f Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 11 Apr 2016 18:14:56 -0700 Subject: Remove CPDF_Object::GetConstString and overrides GetConstString() has sharp edges in that when applied to a CPDF_Number, it must return null whereas GetString() returns a the stringified number, because of the inability to control the lifetime of the underlying allocated string. Deleting this method showed several places where we actually wanted a *String, not a *StringC, so we were re-allocating a string we already had. Review URL: https://codereview.chromium.org/1879683002 --- core/fpdfdoc/cpvt_generateap.cpp | 2 +- core/fpdfdoc/doc_annot.cpp | 6 ++++-- core/fpdfdoc/doc_basic.cpp | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index a837c35801..7b4ad2ff4f 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -451,7 +451,7 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, } // namespace FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") { + if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") { return FALSE; } CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); diff --git a/core/fpdfdoc/doc_annot.cpp b/core/fpdfdoc/doc_annot.cpp index 8650fbd23d..3b90b0b4b5 100644 --- a/core/fpdfdoc/doc_annot.cpp +++ b/core/fpdfdoc/doc_annot.cpp @@ -43,7 +43,7 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) pDict = pAnnots->GetDictAt(i); } m_AnnotList.push_back(new CPDF_Annot(pDict, this)); - if (bRegenerateAP && pDict->GetConstStringBy("Subtype") == "Widget" && + if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && CPDF_InterForm::UpdatingAPEnabled()) { FPDF_GenerateAP(m_pDocument, pDict); } @@ -127,10 +127,12 @@ void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage, CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList) : m_pAnnotDict(pDict), m_pList(pList), - m_sSubtype(m_pAnnotDict->GetConstStringBy("Subtype")) {} + m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {} + CPDF_Annot::~CPDF_Annot() { ClearCachedAP(); } + void CPDF_Annot::ClearCachedAP() { for (const auto& pair : m_APMap) { delete pair.second; diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp index 1cfca7e8ee..e0b71df392 100644 --- a/core/fpdfdoc/doc_basic.cpp +++ b/core/fpdfdoc/doc_basic.cpp @@ -316,7 +316,8 @@ bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { *csFileName = pDict->GetUnicodeTextBy("UF"); if (csFileName->IsEmpty()) { - *csFileName = CFX_WideString::FromLocal(pDict->GetConstStringBy("F")); + *csFileName = + CFX_WideString::FromLocal(pDict->GetStringBy("F").AsStringC()); } if (pDict->GetStringBy("FS") == "URL") return true; -- cgit v1.2.3