summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-08-17 15:39:30 -0700
committerLei Zhang <thestig@chromium.org>2015-08-17 15:39:30 -0700
commita0f67247277f666d80899985eda3c19f3641b9bf (patch)
treefd235c13988e638a44181b9e5a1d1d3c5fd5ad05 /fpdfsdk/src/javascript
parent7dc5cc1c18e04375c19b9793c9da5864660a22f9 (diff)
downloadpdfium-a0f67247277f666d80899985eda3c19f3641b9bf.tar.xz
Merge to XFA: Fix more sign comparison errors.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1290383003 . (cherry picked from commit 9494421208674d2c57a9f864d342f017c0b20902) Review URL: https://codereview.chromium.org/1288603006 .
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp51
1 files changed, 19 insertions, 32 deletions
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index f71ea37c20..38de89d894 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -1498,12 +1498,9 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc,
L"m/d/yy h:MM tt",
L"m/d/yy HH:MM"};
- ASSERT(iIndex < FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
+ if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
iIndex = 0;
+
CJS_Parameters newParams;
CJS_Value val(isolate, cFormats[iIndex]);
newParams.push_back(val);
@@ -1541,12 +1538,9 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc,
L"m/d/yy h:MM tt",
L"m/d/yy HH:MM"};
- ASSERT(iIndex < FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
+ if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
iIndex = 0;
+
CJS_Parameters newParams;
CJS_Value val(isolate, cFormats[iIndex]);
newParams.push_back(val);
@@ -1571,12 +1565,9 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc,
const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss",
L"h:MM:ss tt"};
- ASSERT(iIndex < FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
+ if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
iIndex = 0;
+
CJS_Parameters newParams;
CJS_Value val(isolate, cFormats[iIndex]);
newParams.push_back(val);
@@ -1599,12 +1590,9 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc,
const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss",
L"h:MM:ss tt"};
- ASSERT(iIndex < FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
+ if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
iIndex = 0;
+
CJS_Parameters newParams;
CJS_Value val(isolate, cFormats[iIndex]);
newParams.push_back(val);
@@ -1700,22 +1688,21 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc,
if (wstrMask.IsEmpty())
return TRUE;
- std::wstring wstrValue = valEvent.c_str();
+ const size_t wstrMaskLen = wstrMask.GetLength();
+ const std::wstring wstrValue = valEvent.c_str();
if (pEvent->WillCommit()) {
if (wstrValue.empty())
return TRUE;
- int iIndexMask = 0;
- for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end();
- it++) {
- wchar_t w_Value = *it;
+ size_t iIndexMask = 0;
+ for (const auto& w_Value : wstrValue) {
if (!maskSatisfied(w_Value, wstrMask[iIndexMask]))
break;
iIndexMask++;
}
- if (iIndexMask != wstrMask.GetLength() ||
- (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0)) {
+ if (iIndexMask != wstrMaskLen ||
+ (iIndexMask != wstrValue.size() && wstrMaskLen != 0)) {
Alert(
pContext,
JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
@@ -1731,16 +1718,16 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc,
int iIndexMask = pEvent->SelStart();
- if (wstrValue.length() - (pEvent->SelEnd() - pEvent->SelStart()) +
- wChange.length() >
- (FX_DWORD)wstrMask.GetLength()) {
+ size_t combined_len = wstrValue.length() + wChange.length() -
+ (pEvent->SelEnd() - pEvent->SelStart());
+ if (combined_len > wstrMaskLen) {
Alert(pContext,
JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
pEvent->Rc() = FALSE;
return TRUE;
}
- if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) {
+ if (iIndexMask >= wstrMaskLen && (!wChange.empty())) {
Alert(pContext,
JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
pEvent->Rc() = FALSE;
@@ -1748,7 +1735,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc,
}
for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) {
- if (iIndexMask >= wstrMask.GetLength()) {
+ if (iIndexMask >= wstrMaskLen) {
Alert(pContext,
JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
pEvent->Rc() = FALSE;