summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bytestring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/cfx_bytestring.cpp')
-rw-r--r--core/fxcrt/cfx_bytestring.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp
index 5dcaf613a0..e031c87d2d 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -518,18 +518,18 @@ void CFX_ByteString::Format(const char* pFormat, ...) {
va_end(argList);
}
-FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE nIndex, char ch) {
- FX_STRSIZE nNewLength = m_pData ? m_pData->m_nDataLength : 0;
- nIndex = std::max(nIndex, 0);
- nIndex = std::min(nIndex, nNewLength);
- nNewLength++;
-
- ReallocBeforeWrite(nNewLength);
- memmove(m_pData->m_String + nIndex + 1, m_pData->m_String + nIndex,
- nNewLength - nIndex);
- m_pData->m_String[nIndex] = ch;
- m_pData->m_nDataLength = nNewLength;
- return nNewLength;
+FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE index, char ch) {
+ const FX_STRSIZE cur_length = m_pData ? m_pData->m_nDataLength : 0;
+ if (index != pdfium::clamp(index, 0, cur_length))
+ return cur_length;
+
+ const FX_STRSIZE new_length = cur_length + 1;
+ ReallocBeforeWrite(new_length);
+ memmove(m_pData->m_String + index + 1, m_pData->m_String + index,
+ new_length - index);
+ m_pData->m_String[index] = ch;
+ m_pData->m_nDataLength = new_length;
+ return new_length;
}
CFX_ByteString CFX_ByteString::Right(FX_STRSIZE nCount) const {