summaryrefslogtreecommitdiff
path: root/core/src/fxcrt/fx_basic_wstring.cpp
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2014-07-14 12:13:53 -0700
committerBo Xu <bo_xu@foxitsoftware.com>2014-07-14 12:13:53 -0700
commit8daab317ff959905e926b861a7d2aa876fd10429 (patch)
treed42dbefe9bbdf4492c537253fbc23abf21585fb5 /core/src/fxcrt/fx_basic_wstring.cpp
parent456cde93a928629bbf2ac64bda13ef7923359823 (diff)
downloadpdfium-8daab317ff959905e926b861a7d2aa876fd10429.tar.xz
Fix an out-of-boundary issue for wide string
BUG=381521 R=palmer@chromium.org Review URL: https://codereview.chromium.org/383563002
Diffstat (limited to 'core/src/fxcrt/fx_basic_wstring.cpp')
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index 192579fe54..794630b9e5 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -398,15 +398,10 @@ CFX_WideString CFX_WideString::FromLocal(const char* str, FX_STRSIZE len)
}
CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len)
{
- if (!str) {
+ if (!str || 0 == len) {
return CFX_WideString();
}
- if (len < 0) {
- len = 0;
- while (str[len]) {
- len ++;
- }
- }
+
CFX_UTF8Decoder decoder;
for (FX_STRSIZE i = 0; i < len; i ++) {
decoder.Input(str[i]);
@@ -415,15 +410,10 @@ CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len)
}
CFX_WideString CFX_WideString::FromUTF16LE(const unsigned short* wstr, FX_STRSIZE wlen)
{
- if (!wstr || !wlen) {
+ if (!wstr || 0 == wlen) {
return CFX_WideString();
}
- if (wlen < 0) {
- wlen = 0;
- while (wstr[wlen]) {
- wlen ++;
- }
- }
+
CFX_WideString result;
FX_WCHAR* buf = result.GetBuffer(wlen);
for (int i = 0; i < wlen; i ++) {
@@ -432,6 +422,16 @@ CFX_WideString CFX_WideString::FromUTF16LE(const unsigned short* wstr, FX_STRSIZ
result.ReleaseBuffer(wlen);
return result;
}
+FX_STRSIZE CFX_WideString::WStringLength(const unsigned short* str)
+{
+ FX_STRSIZE len = 0;
+ if (str)
+ while (str[len]) len++;
+ return len;
+}
+
+
+
void CFX_WideString::AllocCopy(CFX_WideString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const
{
// |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It