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

Unified Diff: fpdfsdk/src/javascript/PublicMethods.cpp

Issue 411713003: Fix potential memory violation in CJS_PublicMethods::StrRTrim() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Add newlines. 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/javascript/PublicMethods.cpp
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 55228687bcf86bb394b1e0efcee917fb48044501..a28c5b98ae51f0511dc69ea2db1778d378e54c7c 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -222,16 +222,10 @@ CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
{
FX_LPCWSTR p = pStr;
-
while (*p) p++;
- p--;
- if (p >= pStr)
- {
- while (*p && *p == L' ') p--;
- p++;
- return CFX_WideString(pStr,p-pStr);
- }
- return L"";
+ while (p > pStr && *(p - 1) == L' ') p--;
+
+ return CFX_WideString(pStr, p - pStr);
}
CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
@@ -243,22 +237,16 @@ CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
{
while (*pStr && *pStr == ' ') pStr++;
- return pStr;
+ return pStr;
}
CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
{
FX_LPCSTR p = pStr;
-
while (*p) p++;
- p--;
- if (p >= pStr)
- {
- while (*p && *p == ' ') p--;
- p++;
- return CFX_ByteString(pStr,p-pStr);
- }
- return "";
+ while (p > pStr && *(p - 1) == L' ') p--;
+
+ return CFX_ByteString(pStr,p-pStr);
}
CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698