Remove support for negative params to ReleaseBuffer()
This CL removes the default param value for this method, which was
negative. It also adds in a method to get buffer lengths, so that the
callsites can explictly passing in the length of the buffer if they
were using the default value previously.
BUG=pdfium:828
Change-Id: I0170771ee81970b8b601631015ab3e6e39fea8ea
Reviewed-on: https://pdfium-review.googlesource.com/9790
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index 7025b3e..8323426 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -147,7 +147,7 @@
}
}
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 adef9f6..3c8e532 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -377,7 +377,7 @@
: (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 6e01933..5dcaf61 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -361,12 +361,10 @@
}
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 @@
// 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 519cee3..8bd9f39 100644
--- a/core/fxcrt/cfx_bytestring.h
+++ b/core/fxcrt/cfx_bytestring.h
@@ -79,6 +79,9 @@
}
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 @@
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 d7f265e..4379519 100644
--- a/core/fxcrt/cfx_bytestring_unittest.cpp
+++ b/core/fxcrt/cfx_bytestring_unittest.cpp
@@ -653,7 +653,7 @@
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 @@
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 8937783..b837523 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -488,12 +488,10 @@
}
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 @@
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 938b1e7..02045c5 100644
--- a/core/fxcrt/cfx_widestring.h
+++ b/core/fxcrt/cfx_widestring.h
@@ -75,6 +75,9 @@
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 @@
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 a53e9a3..b743a17 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -618,14 +618,14 @@
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 5c847fc..0a8a59c 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -376,7 +376,7 @@
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 c973612..552bb31 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -482,10 +482,10 @@
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 7cccd2f..c12314f 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -976,11 +976,11 @@
(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 1ec3c97..f1c73a9 100644
--- a/xfa/fde/cfde_txtedtbuf.cpp
+++ b/xfa/fde/cfde_txtedtbuf.cpp
@@ -118,7 +118,7 @@
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 fe79960..f752d91 100644
--- a/xfa/fde/cfde_txtedtdorecord_insert.cpp
+++ b/xfa/fde/cfde_txtedtdorecord_insert.cpp
@@ -18,7 +18,7 @@
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() {}