summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp2
-rw-r--r--core/fpdftext/cpdf_textpagefind.cpp2
-rw-r--r--core/fxcrt/cfx_bytestring.cpp6
-rw-r--r--core/fxcrt/cfx_bytestring.h5
-rw-r--r--core/fxcrt/cfx_bytestring_unittest.cpp4
-rw-r--r--core/fxcrt/cfx_widestring.cpp6
-rw-r--r--core/fxcrt/cfx_widestring.h5
-rw-r--r--core/fxcrt/cfx_widestring_unittest.cpp4
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp2
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp4
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp10
-rw-r--r--xfa/fde/cfde_txtedtbuf.cpp2
-rw-r--r--xfa/fde/cfde_txtedtdorecord_insert.cpp2
13 files changed, 28 insertions, 26 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);
}
}
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 5c847fc1df..0a8a59cfda 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -376,7 +376,7 @@ void CPDFSDK_FormFillEnvironment::GotoURL(CPDFXFA_Context* document,
CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
- bsTo.ReleaseBuffer();
+ bsTo.ReleaseBuffer(bsTo.GetStringLength());
}
void CPDFSDK_FormFillEnvironment::GetPageViewRect(CPDFXFA_Page* page,
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index c9736126d3..552bb31af2 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -482,10 +482,10 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
fdfEncodedData << name_b.GetBuffer(name_b.GetLength());
- name_b.ReleaseBuffer();
+ name_b.ReleaseBuffer(name_b.GetStringLength());
fdfEncodedData << "=";
fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength());
- csValue_b.ReleaseBuffer();
+ csValue_b.ReleaseBuffer(csValue_b.GetStringLength());
if (i != pFields->GetCount() - 1)
fdfEncodedData << "&";
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 7cccd2fb11..c12314f88d 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -976,11 +976,11 @@ bool CPDFXFA_DocEnvironment::SubmitDataInternal(CXFA_FFDoc* hDoc,
(FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
pFormFillEnv->EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg);
- bsTo.ReleaseBuffer();
- bsCC.ReleaseBuffer();
- bsBcc.ReleaseBuffer();
- bsSubject.ReleaseBuffer();
- bsMsg.ReleaseBuffer();
+ bsTo.ReleaseBuffer(bsTo.GetStringLength());
+ bsCC.ReleaseBuffer(bsCC.GetStringLength());
+ bsBcc.ReleaseBuffer(bsBcc.GetStringLength());
+ bsSubject.ReleaseBuffer(bsSubject.GetStringLength());
+ bsMsg.ReleaseBuffer(bsMsg.GetStringLength());
} else {
// HTTP or FTP
CFX_WideString ws;
diff --git a/xfa/fde/cfde_txtedtbuf.cpp b/xfa/fde/cfde_txtedtbuf.cpp
index 1ec3c9721a..f1c73a9529 100644
--- a/xfa/fde/cfde_txtedtbuf.cpp
+++ b/xfa/fde/cfde_txtedtbuf.cpp
@@ -118,7 +118,7 @@ CFX_WideString CFDE_TxtEdtBuf::GetRange(int32_t nBegin, int32_t nLength) const {
lpDstBuf += nCopyLength;
nCopyLength = chunkHeader->nUsed;
}
- wsText.ReleaseBuffer();
+ wsText.ReleaseBuffer(wsText.GetStringLength());
return wsText;
}
diff --git a/xfa/fde/cfde_txtedtdorecord_insert.cpp b/xfa/fde/cfde_txtedtdorecord_insert.cpp
index fe79960ebc..f752d911f6 100644
--- a/xfa/fde/cfde_txtedtdorecord_insert.cpp
+++ b/xfa/fde/cfde_txtedtdorecord_insert.cpp
@@ -18,7 +18,7 @@ CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert(
ASSERT(pEngine);
wchar_t* lpBuffer = m_wsInsert.GetBuffer(nLength);
memcpy(lpBuffer, lpText, nLength * sizeof(wchar_t));
- m_wsInsert.ReleaseBuffer();
+ m_wsInsert.ReleaseBuffer(m_wsInsert.GetStringLength());
}
CFDE_TxtEdtDoRecord_Insert::~CFDE_TxtEdtDoRecord_Insert() {}