diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_utility.cpp | 2 | ||||
-rw-r--r-- | core/fpdftext/cpdf_textpagefind.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring.cpp | 6 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring.h | 5 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.cpp | 6 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.h | 5 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring_unittest.cpp | 4 |
8 files changed, 18 insertions, 16 deletions
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp index 7025b3e7d8..8323426e74 100644 --- a/core/fpdfapi/parser/fpdf_parser_utility.cpp +++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp @@ -147,7 +147,7 @@ CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig) { } } dest_buf[dest_len] = 0; - res.ReleaseBuffer(); + res.ReleaseBuffer(res.GetStringLength()); return res; } diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp index adef9f6c0c..3c8e532a7f 100644 --- a/core/fpdftext/cpdf_textpagefind.cpp +++ b/core/fpdftext/cpdf_textpagefind.cpp @@ -377,7 +377,7 @@ bool CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString, : (int)FXSYS_wcslen(lpszFullString); ASSERT(nLen >= 0); memcpy(rString.GetBuffer(nLen), lpszFullString, nLen * sizeof(wchar_t)); - rString.ReleaseBuffer(); + rString.ReleaseBuffer(rString.GetStringLength()); return true; } diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp index 6e01933682..5dcaf613a0 100644 --- a/core/fxcrt/cfx_bytestring.cpp +++ b/core/fxcrt/cfx_bytestring.cpp @@ -361,12 +361,10 @@ void CFX_ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) { } void CFX_ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { + ASSERT(nNewLength >= 0); if (!m_pData) return; - if (nNewLength == -1) - nNewLength = FXSYS_strlen(m_pData->m_String); - nNewLength = std::min(nNewLength, m_pData->m_nAllocLength); if (nNewLength == 0) { clear(); @@ -507,7 +505,7 @@ void CFX_ByteString::FormatV(const char* pFormat, va_list argList) { // a terminating NUL that's not included in nMaxLen. memset(m_pData->m_String, 0, nMaxLen + 1); vsnprintf(m_pData->m_String, nMaxLen + 1, pFormat, argListSave); - ReleaseBuffer(); + ReleaseBuffer(GetStringLength()); } } va_end(argListSave); diff --git a/core/fxcrt/cfx_bytestring.h b/core/fxcrt/cfx_bytestring.h index 519cee39d4..8bd9f39fc0 100644 --- a/core/fxcrt/cfx_bytestring.h +++ b/core/fxcrt/cfx_bytestring.h @@ -79,6 +79,9 @@ class CFX_ByteString { } FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } + FX_STRSIZE GetStringLength() const { + return m_pData ? FXSYS_strlen(m_pData->m_String) : 0; + } bool IsEmpty() const { return !GetLength(); } int Compare(const CFX_ByteStringC& str) const; @@ -122,7 +125,7 @@ class CFX_ByteString { void Reserve(FX_STRSIZE len); char* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len = -1); + void ReleaseBuffer(FX_STRSIZE len); CFX_ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const; CFX_ByteString Left(FX_STRSIZE count) const; diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp index d7f265e32a..4379519046 100644 --- a/core/fxcrt/cfx_bytestring_unittest.cpp +++ b/core/fxcrt/cfx_bytestring_unittest.cpp @@ -653,7 +653,7 @@ TEST(fxcrt, ByteStringGetBuffer) { char* buffer = str.GetBuffer(12); // NOLINTNEXTLINE(runtime/printf) strcpy(buffer, "clams"); - str.ReleaseBuffer(); + str.ReleaseBuffer(str.GetStringLength()); EXPECT_EQ("clams", str); } { @@ -661,7 +661,7 @@ TEST(fxcrt, ByteStringGetBuffer) { char* buffer = str.GetBuffer(12); // NOLINTNEXTLINE(runtime/printf) strcpy(buffer + 2, "ams"); - str.ReleaseBuffer(); + str.ReleaseBuffer(str.GetStringLength()); EXPECT_EQ("clams", str); } } diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp index 8937783863..b83752369b 100644 --- a/core/fxcrt/cfx_widestring.cpp +++ b/core/fxcrt/cfx_widestring.cpp @@ -488,12 +488,10 @@ void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) { } void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { + ASSERT(nNewLength >= 0); if (!m_pData) return; - if (nNewLength == -1) - nNewLength = FXSYS_wcslen(m_pData->m_String); - nNewLength = std::min(nNewLength, m_pData->m_nAllocLength); if (nNewLength == 0) { clear(); @@ -651,7 +649,7 @@ bool CFX_WideString::TryVSWPrintf(FX_STRSIZE size, memset(m_pData->m_String, 0, (size + 1) * sizeof(wchar_t)); int ret = vswprintf(m_pData->m_String, size + 1, pFormat, argList); bool bSufficientBuffer = ret >= 0 || m_pData->m_String[size - 1] == 0; - ReleaseBuffer(); + ReleaseBuffer(GetStringLength()); return bSufficientBuffer; } diff --git a/core/fxcrt/cfx_widestring.h b/core/fxcrt/cfx_widestring.h index 938b1e7958..02045c5c09 100644 --- a/core/fxcrt/cfx_widestring.h +++ b/core/fxcrt/cfx_widestring.h @@ -75,6 +75,9 @@ class CFX_WideString { void clear() { m_pData.Reset(); } FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } + FX_STRSIZE GetStringLength() const { + return m_pData ? FXSYS_wcslen(m_pData->m_String) : 0; + } bool IsEmpty() const { return !GetLength(); } const CFX_WideString& operator=(const wchar_t* str); @@ -135,7 +138,7 @@ class CFX_WideString { void Reserve(FX_STRSIZE len); wchar_t* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len = -1); + void ReleaseBuffer(FX_STRSIZE len); int GetInteger() const; float GetFloat() const; diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp index a53e9a35e2..b743a17fd1 100644 --- a/core/fxcrt/cfx_widestring_unittest.cpp +++ b/core/fxcrt/cfx_widestring_unittest.cpp @@ -618,14 +618,14 @@ TEST(fxcrt, WideStringGetBuffer) { CFX_WideString str; wchar_t* buffer = str.GetBuffer(12); wcscpy(buffer, L"clams"); - str.ReleaseBuffer(); + str.ReleaseBuffer(str.GetStringLength()); EXPECT_EQ(L"clams", str); } { CFX_WideString str(L"cl"); wchar_t* buffer = str.GetBuffer(12); wcscpy(buffer + 2, L"ams"); - str.ReleaseBuffer(); + str.ReleaseBuffer(str.GetStringLength()); EXPECT_EQ(L"clams", str); } } |