From 4d31d0c653cf66f72bdef7cebbf7cff45d33f6c6 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 19 Apr 2016 14:11:59 -0700 Subject: Remove a few more char* members from structs/classes. This is a result of looking for the anti-paterns /char\*\sm_/ and /m_.*=.*\.c_str/ which indicate that a class may be using the contents of a string without extending the lifetime of the underlying storage. Along the way, change to uint8_t in fx_dib; this is unrelated but avoids grep hits (it is binary, not chars anyways). Also remove two string operators that make it easy to assign in a manner that does not extend contents lifetime. Review URL: https://codereview.chromium.org/1902953002 --- core/fpdfdoc/doc_form.cpp | 14 ++++++++------ core/fxcrt/include/fx_string.h | 16 ---------------- core/fxge/dib/dib_int.h | 4 ++-- xfa/fxfa/app/xfa_textlayout.cpp | 4 ++-- xfa/fxfa/parser/xfa_document_imp.cpp | 2 +- xfa/fxfa/parser/xfa_object_imp.cpp | 2 +- 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/core/fpdfdoc/doc_form.cpp b/core/fpdfdoc/doc_form.cpp index 5062b45452..d356a5c0e1 100644 --- a/core/fpdfdoc/doc_form.cpp +++ b/core/fpdfdoc/doc_form.cpp @@ -48,11 +48,12 @@ CFX_WideString FPDFDOC_FDF_GetFieldValue(const CPDF_Dictionary& pFieldDict, class CFieldNameExtractor { public: - explicit CFieldNameExtractor(const CFX_WideString& full_name) { - m_pStart = full_name.c_str(); - m_pEnd = m_pStart + full_name.GetLength(); - m_pCur = m_pStart; + explicit CFieldNameExtractor(const CFX_WideString& full_name) + : m_FullName(full_name) { + m_pCur = m_FullName.c_str(); + m_pEnd = m_pCur + m_FullName.GetLength(); } + void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { pSubName = m_pCur; while (m_pCur < m_pEnd && m_pCur[0] != L'.') { @@ -65,10 +66,11 @@ class CFieldNameExtractor { } protected: - const FX_WCHAR* m_pStart; - const FX_WCHAR* m_pEnd; + CFX_WideString m_FullName; const FX_WCHAR* m_pCur; + const FX_WCHAR* m_pEnd; }; + class CFieldTree { public: struct _Node { diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index 2fabee39cf..10a70d9334 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -74,8 +74,6 @@ class CFX_ByteStringC { return *this; } - CFX_ByteStringC& operator=(const CFX_ByteString& src); - bool operator==(const char* ptr) const { return FXSYS_strlen(ptr) == m_Length && FXSYS_memcmp(ptr, m_Ptr, m_Length) == 0; @@ -285,12 +283,6 @@ class CFX_ByteString { friend class fxcrt_ByteStringConcat_Test; }; -inline CFX_ByteStringC& CFX_ByteStringC::operator=(const CFX_ByteString& src) { - m_Ptr = src.raw_str(); - m_Length = src.GetLength(); - return *this; -} - inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { return rhs == lhs; } @@ -398,8 +390,6 @@ class CFX_WideStringC { return *this; } - CFX_WideStringC& operator=(const CFX_WideString& src); - bool operator==(const wchar_t* ptr) const { return FXSYS_wcslen(ptr) == m_Length && wmemcmp(ptr, m_Ptr, m_Length) == 0; } @@ -611,12 +601,6 @@ class CFX_WideString { friend class fxcrt_WideStringConcatInPlace_Test; }; -inline CFX_WideStringC& CFX_WideStringC::operator=(const CFX_WideString& src) { - m_Ptr = src.c_str(); - m_Length = src.GetLength(); - return *this; -} - inline CFX_WideString operator+(const CFX_WideStringC& str1, const CFX_WideStringC& str2) { return CFX_WideString(str1, str2); diff --git a/core/fxge/dib/dib_int.h b/core/fxge/dib/dib_int.h index 23dd0babba..ebb1ddc0ed 100644 --- a/core/fxge/dib/dib_int.h +++ b/core/fxge/dib/dib_int.h @@ -86,8 +86,8 @@ class CStretchEngine { int m_SrcWidth, m_SrcHeight; int m_SrcPitch, m_InterPitch; int m_ExtraMaskPitch; - unsigned char* m_pInterBuf; - unsigned char* m_pExtraAlphaBuf; + uint8_t* m_pInterBuf; + uint8_t* m_pExtraAlphaBuf; int m_TransMethod; int m_Flags; CWeightTable m_WeightTable; diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp index 80342a383e..532d6f54ce 100644 --- a/xfa/fxfa/app/xfa_textlayout.cpp +++ b/xfa/fxfa/app/xfa_textlayout.cpp @@ -37,8 +37,8 @@ void CXFA_CSSTagProvider::GetNextAttribute(FX_POSITION& pos, CFX_WideString* pName = NULL; CFX_WideString* pValue = NULL; m_Attributes.GetNextAssoc(pos, (void*&)pName, (void*&)pValue); - wsAttr = *pName; - wsValue = *pValue; + wsAttr = pName->AsStringC(); + wsValue = pValue->AsStringC(); } void CXFA_CSSTagProvider::SetAttribute(const CFX_WideString& wsAttr, const CFX_WideString& wsValue) { diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index bdcfba47cb..39bdf2503c 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -388,7 +388,7 @@ void CXFA_Document::DoProtoMerge() { !wsUseVal.IsEmpty()) { FX_STRSIZE uSharpPos = wsUseVal.Find('#'); if (uSharpPos < 0) { - wsURI = wsUseVal; + wsURI = wsUseVal.AsStringC(); } else { wsURI = CFX_WideStringC(wsUseVal.c_str(), uSharpPos); FX_STRSIZE uLen = wsUseVal.GetLength(); diff --git a/xfa/fxfa/parser/xfa_object_imp.cpp b/xfa/fxfa/parser/xfa_object_imp.cpp index 306bd0f173..93b596ae99 100644 --- a/xfa/fxfa/parser/xfa_object_imp.cpp +++ b/xfa/fxfa/parser/xfa_object_imp.cpp @@ -4084,7 +4084,7 @@ FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, if (eAttr == XFA_ATTRIBUTE_Value) { CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); if (pStr) { - wsValue = *pStr; + wsValue = pStr->AsStringC(); return TRUE; } } else { -- cgit v1.2.3