summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_widestring.h
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-25 15:34:41 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-25 19:57:25 +0000
commited48c1a42b2f9a0c8cb04185c180c6424bad3b83 (patch)
tree34745df62b9982021dfa990b1cec824674033236 /core/fxcrt/cfx_widestring.h
parent175a8588f4290df8ec32d697c0248eb5c6b2c396 (diff)
downloadpdfium-ed48c1a42b2f9a0c8cb04185c180c6424bad3b83.tar.xz
Add help IsValid* methods to string classeschromium/3198chromium/3197
The various string classes, CFX_ByteString, CFX_ByteStringC, CFX_WideString, and CFX_WideStringC, have many conditionals that are effectively determining if a value is a valid index or length. This CL refactors the logic into one place per class, so it only needs to be changed once if its behaviour needs to change. It also make the some of the methods stricter on the inputs they will accept. BUG=pdfium:828 Change-Id: Iadcdaa34a6d862a2804485770027179c89dc6956 Reviewed-on: https://pdfium-review.googlesource.com/12030 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_widestring.h')
-rw-r--r--core/fxcrt/cfx_widestring.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/core/fxcrt/cfx_widestring.h b/core/fxcrt/cfx_widestring.h
index a6d0eca044..242138853b 100644
--- a/core/fxcrt/cfx_widestring.h
+++ b/core/fxcrt/cfx_widestring.h
@@ -81,6 +81,14 @@ class CFX_WideString {
}
bool IsEmpty() const { return !GetLength(); }
+ bool IsValidIndex(FX_STRSIZE index) const {
+ return 0 <= index && index < GetLength();
+ }
+
+ bool IsValidLength(FX_STRSIZE length) const {
+ return 0 <= length && length <= GetLength();
+ }
+
const CFX_WideString& operator=(const wchar_t* str);
const CFX_WideString& operator=(const CFX_WideString& stringSrc);
const CFX_WideString& operator=(const CFX_WideStringC& stringSrc);
@@ -103,7 +111,7 @@ class CFX_WideString {
bool operator<(const CFX_WideString& str) const;
CharType operator[](const FX_STRSIZE index) const {
- ASSERT(index >= 0 && index < GetLength());
+ ASSERT(IsValidIndex(index));
return m_pData ? m_pData->m_String[index] : 0;
}