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/fpdfapi/fpdf_parser/cpdf_array.cpp | 6 ---- core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp | 13 --------- core/fpdfapi/fpdf_parser/cpdf_name.cpp | 4 --- core/fpdfapi/fpdf_parser/cpdf_object.cpp | 4 --- core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp | 32 ---------------------- core/fpdfapi/fpdf_parser/cpdf_reference.cpp | 5 ---- core/fpdfapi/fpdf_parser/cpdf_string.cpp | 4 --- core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 4 +-- core/fpdfapi/fpdf_parser/include/cpdf_array.h | 1 - core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h | 3 -- core/fpdfapi/fpdf_parser/include/cpdf_name.h | 1 - core/fpdfapi/fpdf_parser/include/cpdf_object.h | 3 -- core/fpdfapi/fpdf_parser/include/cpdf_reference.h | 1 - core/fpdfapi/fpdf_parser/include/cpdf_string.h | 1 - 14 files changed, 2 insertions(+), 80 deletions(-) (limited to 'core/fpdfapi/fpdf_parser') diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp index e2279c8e1d..d588f339a7 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp @@ -92,12 +92,6 @@ CFX_ByteString CPDF_Array::GetStringAt(size_t i) const { return m_Objects.at(i)->GetString(); } -CFX_ByteStringC CPDF_Array::GetConstStringAt(size_t i) const { - if (i >= m_Objects.size()) - return CFX_ByteStringC(); - return m_Objects.at(i)->GetConstString(); -} - int CPDF_Array::GetIntegerAt(size_t i) const { if (i >= m_Objects.size()) return 0; diff --git a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp index 5f86a7bbc2..f03b14d8e1 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp @@ -68,12 +68,6 @@ CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key) const { return p ? p->GetString() : CFX_ByteString(); } -CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( - const CFX_ByteStringC& key) const { - CPDF_Object* p = GetObjectBy(key); - return p ? p->GetConstString() : CFX_ByteStringC(); -} - CFX_WideString CPDF_Dictionary::GetUnicodeTextBy( const CFX_ByteStringC& key) const { CPDF_Object* p = GetObjectBy(key); @@ -88,13 +82,6 @@ CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key, return p ? p->GetString() : CFX_ByteString(def); } -CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( - const CFX_ByteStringC& key, - const CFX_ByteStringC& def) const { - CPDF_Object* p = GetObjectBy(key); - return p ? p->GetConstString() : CFX_ByteStringC(def); -} - int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key) const { CPDF_Object* p = GetObjectBy(key); return p ? p->GetInteger() : 0; diff --git a/core/fpdfapi/fpdf_parser/cpdf_name.cpp b/core/fpdfapi/fpdf_parser/cpdf_name.cpp index d641374547..2999772aec 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_name.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_name.cpp @@ -28,10 +28,6 @@ CFX_ByteString CPDF_Name::GetString() const { return m_Name; } -CFX_ByteStringC CPDF_Name::GetConstString() const { - return m_Name.AsStringC(); -} - void CPDF_Name::SetString(const CFX_ByteString& str) { m_Name = str; } diff --git a/core/fpdfapi/fpdf_parser/cpdf_object.cpp b/core/fpdfapi/fpdf_parser/cpdf_object.cpp index 9a190a7308..86b9449cf8 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object.cpp @@ -33,10 +33,6 @@ CFX_ByteString CPDF_Object::GetString() const { return CFX_ByteString(); } -CFX_ByteStringC CPDF_Object::GetConstString() const { - return CFX_ByteStringC(); -} - CFX_WideString CPDF_Object::GetUnicodeText() const { return CFX_WideString(); } diff --git a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp index 362991f723..3d0947d643 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp @@ -34,7 +34,6 @@ void TestArrayAccessors(const CPDF_Array* arr, CPDF_Dictionary* dict_val, CPDF_Stream* stream_val) { EXPECT_STREQ(str_val, arr->GetStringAt(index).c_str()); - EXPECT_STREQ(const_str_val, arr->GetConstStringAt(index).c_str()); EXPECT_EQ(int_val, arr->GetIntegerAt(index)); EXPECT_EQ(float_val, arr->GetNumberAt(index)); EXPECT_EQ(float_val, arr->GetFloatAt(index)); @@ -199,33 +198,6 @@ TEST_F(PDFObjectsTest, GetString) { } } -TEST_F(PDFObjectsTest, GetConstString) { - const char* direct_obj_results[] = { - nullptr, nullptr, nullptr, nullptr, "A simple test", "\t\n", - "space", nullptr, nullptr, nullptr, nullptr}; - // Check for direct objects. - for (size_t i = 0; i < m_DirectObjs.size(); ++i) { - if (!direct_obj_results[i]) { - EXPECT_EQ(direct_obj_results[i], - m_DirectObjs[i]->GetConstString().c_str()); - } else { - EXPECT_STREQ(direct_obj_results[i], - m_DirectObjs[i]->GetConstString().c_str()); - } - } - // Check indirect references. - const char* indirect_obj_results[] = {nullptr, nullptr, "\t\n", "space", - nullptr, nullptr, nullptr}; - for (size_t i = 0; i < m_RefObjs.size(); ++i) { - if (!indirect_obj_results[i]) { - EXPECT_EQ(nullptr, m_RefObjs[i]->GetConstString().c_str()); - } else { - EXPECT_STREQ(indirect_obj_results[i], - m_RefObjs[i]->GetConstString().c_str()); - } - } -} - TEST_F(PDFObjectsTest, GetUnicodeText) { const wchar_t* direct_obj_results[] = { L"", L"", L"", L"", L"A simple test", @@ -668,16 +640,12 @@ TEST(PDFArrayTest, GetTypeAt) { const char* const expected_str[] = { "true", "false", "0", "-1234", "2345", "0.05", "", "It is a test!", "NAME", "test", "", "", "", ""}; - const char* const expected_cstr[] = { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - "It is a test!", "NAME", "test", nullptr, nullptr, nullptr, nullptr}; const int expected_int[] = {1, 0, 0, -1234, 2345, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < arr->GetCount(); ++i) { EXPECT_STREQ(expected_str[i], arr->GetStringAt(i).c_str()); - EXPECT_STREQ(expected_cstr[i], arr->GetConstStringAt(i).c_str()); EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i)); EXPECT_EQ(expected_float[i], arr->GetNumberAt(i)); EXPECT_EQ(expected_float[i], arr->GetFloatAt(i)); diff --git a/core/fpdfapi/fpdf_parser/cpdf_reference.cpp b/core/fpdfapi/fpdf_parser/cpdf_reference.cpp index 9053d08b36..007423e5fb 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_reference.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_reference.cpp @@ -22,11 +22,6 @@ CFX_ByteString CPDF_Reference::GetString() const { return obj ? obj->GetString() : CFX_ByteString(); } -CFX_ByteStringC CPDF_Reference::GetConstString() const { - CPDF_Object* obj = SafeGetDirect(); - return obj ? obj->GetConstString() : CFX_ByteStringC(); -} - FX_FLOAT CPDF_Reference::GetNumber() const { CPDF_Object* obj = SafeGetDirect(); return obj ? obj->GetNumber() : 0; diff --git a/core/fpdfapi/fpdf_parser/cpdf_string.cpp b/core/fpdfapi/fpdf_parser/cpdf_string.cpp index 52f6a5a836..4b92596242 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_string.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_string.cpp @@ -31,10 +31,6 @@ CFX_ByteString CPDF_String::GetString() const { return m_String; } -CFX_ByteStringC CPDF_String::GetConstString() const { - return m_String.AsStringC(); -} - void CPDF_String::SetString(const CFX_ByteString& str) { m_String = str; } diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 11d9e524ee..f81f41c89f 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -350,11 +350,11 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf, pParams = nullptr; for (size_t i = 0; i < pDecoders->GetCount(); i++) { - DecoderList.push_back(pDecoders->GetConstStringAt(i)); + DecoderList.push_back(pDecoders->GetStringAt(i)); ParamList.Add(pParams ? pParamsArray->GetDictAt(i) : nullptr); } } else { - DecoderList.push_back(pDecoder->GetConstString()); + DecoderList.push_back(pDecoder->GetString()); ParamList.Add(pParams ? pParams->GetDict() : nullptr); } uint8_t* last_buf = (uint8_t*)src_buf; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_array.h b/core/fpdfapi/fpdf_parser/include/cpdf_array.h index 506a6bc338..ac3bf41b45 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_array.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_array.h @@ -30,7 +30,6 @@ class CPDF_Array : public CPDF_Object { CPDF_Object* GetObjectAt(size_t index) const; CPDF_Object* GetDirectObjectAt(size_t index) const; CFX_ByteString GetStringAt(size_t index) const; - CFX_ByteStringC GetConstStringAt(size_t index) const; int GetIntegerAt(size_t index) const; FX_FLOAT GetNumberAt(size_t index) const; CPDF_Dictionary* GetDictAt(size_t index) const; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h index 82abc35c02..c39370e6ec 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h @@ -34,11 +34,8 @@ class CPDF_Dictionary : public CPDF_Object { CPDF_Object* GetObjectBy(const CFX_ByteStringC& key) const; CPDF_Object* GetDirectObjectBy(const CFX_ByteStringC& key) const; CFX_ByteString GetStringBy(const CFX_ByteStringC& key) const; - CFX_ByteStringC GetConstStringBy(const CFX_ByteStringC& key) const; CFX_ByteString GetStringBy(const CFX_ByteStringC& key, const CFX_ByteStringC& default_str) const; - CFX_ByteStringC GetConstStringBy(const CFX_ByteStringC& key, - const CFX_ByteStringC& default_str) const; CFX_WideString GetUnicodeTextBy(const CFX_ByteStringC& key) const; int GetIntegerBy(const CFX_ByteStringC& key) const; int GetIntegerBy(const CFX_ByteStringC& key, int default_int) const; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_name.h b/core/fpdfapi/fpdf_parser/include/cpdf_name.h index 62fd5c14a8..bebccb5841 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_name.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_name.h @@ -19,7 +19,6 @@ class CPDF_Name : public CPDF_Object { Type GetType() const override; CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; CFX_ByteString GetString() const override; - CFX_ByteStringC GetConstString() const override; CFX_WideString GetUnicodeText() const override; void SetString(const CFX_ByteString& str) override; bool IsName() const override; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_object.h b/core/fpdfapi/fpdf_parser/include/cpdf_object.h index 6cdaaf58fd..c0c442157f 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_object.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_object.h @@ -46,9 +46,6 @@ class CPDF_Object { void Release(); virtual CFX_ByteString GetString() const; - - // Note: |this| must outlive the use of |GetConstString|'s result. - virtual CFX_ByteStringC GetConstString() const; virtual CFX_WideString GetUnicodeText() const; virtual FX_FLOAT GetNumber() const; virtual int GetInteger() const; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_reference.h b/core/fpdfapi/fpdf_parser/include/cpdf_reference.h index b7d826902b..49b698eacb 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_reference.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_reference.h @@ -20,7 +20,6 @@ class CPDF_Reference : public CPDF_Object { CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; CPDF_Object* GetDirect() const override; CFX_ByteString GetString() const override; - CFX_ByteStringC GetConstString() const override; FX_FLOAT GetNumber() const override; int GetInteger() const override; CPDF_Dictionary* GetDict() const override; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_string.h b/core/fpdfapi/fpdf_parser/include/cpdf_string.h index 77e41ecd6a..c17cc182f7 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_string.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_string.h @@ -21,7 +21,6 @@ class CPDF_String : public CPDF_Object { Type GetType() const override; CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; CFX_ByteString GetString() const override; - CFX_ByteStringC GetConstString() const override; CFX_WideString GetUnicodeText() const override; void SetString(const CFX_ByteString& str) override; bool IsString() const override; -- cgit v1.2.3