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

Unified Diff: core/src/fxcrt/fx_basic_wstring.cpp

Issue 383563002: Fix an out-of-boundary issue for wide string (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Add WStringLength function Created 6 years, 5 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/src/fxcrt/fx_basic_util.cpp ('k') | core/src/fxge/win32/fx_win32_device.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcrt/fx_basic_wstring.cpp
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index 192579fe547e1dda087542b83f4a1a4a59135203..794630b9e5e488b0f3b5c70e99b49feaf36c4472 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
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | core/src/fxge/win32/fx_win32_device.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698