summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt')
-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
6 files changed, 16 insertions, 14 deletions
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);
}
}