Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: core/fxcrt/fx_basic_wstring.cpp

Issue 1847193002: Beef up unit test for CFX_ByteString and CFX_WideString. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Few more cases. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | core/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_basic_wstring.cpp
diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp
index aa62b5e3560195b005774243b5290439f56a63ab..642b75eafe35304badc2102201a184dd2576daa6 100644
--- a/core/fxcrt/fx_basic_wstring.cpp
+++ b/core/fxcrt/fx_basic_wstring.cpp
@@ -441,27 +441,20 @@ CFX_WideString CFX_WideString::Left(FX_STRSIZE nCount) const {
return dest;
}
CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const {
+ if (!m_pData)
+ return CFX_WideString();
+
return Mid(nFirst, m_pData->m_nDataLength - nFirst);
}
CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const {
- if (!m_pData) {
+ if (!m_pData)
return CFX_WideString();
- }
- if (nFirst < 0) {
- nFirst = 0;
- }
- if (nCount < 0) {
- nCount = 0;
- }
- if (nFirst + nCount > m_pData->m_nDataLength) {
- nCount = m_pData->m_nDataLength - nFirst;
- }
- if (nFirst > m_pData->m_nDataLength) {
- nCount = 0;
- }
- if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) {
+
+ nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength);
+ nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst);
+ if (nFirst == 0 && nCount == m_pData->m_nDataLength)
return *this;
- }
+
CFX_WideString dest;
AllocCopy(dest, nCount, nFirst);
return dest;
« no previous file with comments | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | core/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698