From 94fb74c3137ab4f9f817f4cfb14e0a68a677422b Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 30 Aug 2016 06:37:54 -0700 Subject: More better const-ness in CFX_CountRef<> There are a couple of places where code is calling GetObject() that should be calling GetPrivateCopy(), but works because the value may not be shared at the time. This just makes it safer. Review-Url: https://codereview.chromium.org/2290863002 --- core/fpdfapi/fpdf_page/cpdf_textobject.cpp | 4 ++-- core/fpdfapi/fpdf_page/cpdf_textstate.h | 2 +- core/fpdfapi/fpdf_page/include/cpdf_path.h | 4 ++-- core/fxcrt/include/cfx_count_ref.h | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp index bd17dea86e..af6ae06741 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp @@ -133,11 +133,11 @@ CPDF_PageObject::Type CPDF_TextObject::GetType() const { } void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { - m_TextState.GetPrivateCopy(); CFX_Matrix text_matrix; GetTextMatrix(&text_matrix); text_matrix.Concat(matrix); - FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); + + FX_FLOAT* pTextMatrix = m_TextState.GetMutableMatrix(); pTextMatrix[0] = text_matrix.GetA(); pTextMatrix[1] = text_matrix.GetC(); pTextMatrix[2] = text_matrix.GetB(); diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.h b/core/fpdfapi/fpdf_page/cpdf_textstate.h index 59c988de06..235bdf1aa1 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textstate.h +++ b/core/fpdfapi/fpdf_page/cpdf_textstate.h @@ -18,8 +18,8 @@ class CPDF_TextState : public CFX_CountRef { void SetFont(CPDF_Font* pFont); FX_FLOAT GetFontSize() const { return GetObject()->m_FontSize; } - FX_FLOAT* GetMatrix() { return GetObject()->m_Matrix; } const FX_FLOAT* GetMatrix() const { return GetObject()->m_Matrix; } + FX_FLOAT* GetMutableMatrix() { return GetPrivateCopy()->m_Matrix; } FX_FLOAT GetFontSizeV() const; FX_FLOAT GetFontSizeH() const; diff --git a/core/fpdfapi/fpdf_page/include/cpdf_path.h b/core/fpdfapi/fpdf_page/include/cpdf_path.h index 98de696004..e0ffa8c1dd 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_path.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_path.h @@ -30,14 +30,14 @@ class CPDF_Path : public CFX_CountRef { GetPrivateCopy()->Transform(pMatrix); } void Append(const CPDF_Path& other, const CFX_Matrix* pMatrix) { - GetObject()->Append(other.GetObject(), pMatrix); + GetPrivateCopy()->Append(other.GetObject(), pMatrix); } void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top) { - GetObject()->AppendRect(left, bottom, right, top); + GetPrivateCopy()->AppendRect(left, bottom, right, top); } }; diff --git a/core/fxcrt/include/cfx_count_ref.h b/core/fxcrt/include/cfx_count_ref.h index 817ce95add..954b72bf88 100644 --- a/core/fxcrt/include/cfx_count_ref.h +++ b/core/fxcrt/include/cfx_count_ref.h @@ -30,7 +30,6 @@ class CFX_CountRef { } void SetNull() { m_pObject.Reset(); } - ObjClass* GetObject() { return m_pObject.Get(); } const ObjClass* GetObject() const { return m_pObject.Get(); } template -- cgit v1.2.3