summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-01 15:16:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-01 19:35:49 +0000
commitda129ab38c3fb6ed3de85ffb6f8938eb31130a53 (patch)
tree1ed3980d91ae9258f917124d69f0276260e34b71 /fpdfsdk
parentde7c9620c37486413e1f7db4567b4b0cea6a857f (diff)
downloadpdfium-da129ab38c3fb6ed3de85ffb6f8938eb31130a53.tar.xz
Replace raw value for constant error value in string operations
Currently Find() and other methods that return a FX_STRSIZE return -1 to indicate error/failure. This means that there is a lot of magic numbers and magic checks floating around. The standard library for similar operations uses a npos constant. This CL implements FX_STRNPOS, and replaces usages of magic number checking. It also does some type cleanup along the way where it was obvious that FX_STRSIZE should be being used. Removing the magic numbers should make eventually changing FX_STRSIZE to be unsigned easier in the future. BUG=pdfium:828 Change-Id: I67e481e44cf2f75a1698afa8fbee4f375a74c490 Reviewed-on: https://pdfium-review.googlesource.com/9651 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfedittext.cpp2
-rw-r--r--fpdfsdk/fpdfppo.cpp12
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp22
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp9
4 files changed, 23 insertions, 22 deletions
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
index 02bf722462..f498917a19 100644
--- a/fpdfsdk/fpdfedittext.cpp
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -39,7 +39,7 @@ CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc,
int flags = 0;
if (FXFT_Is_Face_fixedwidth(pFont->GetFace()))
flags |= FXFONT_FIXED_PITCH;
- if (font_name.Find("Serif") > -1)
+ if (font_name.Find("Serif") != FX_STRNPOS)
flags |= FXFONT_SERIF;
if (FXFT_Is_Face_Italic(pFont->GetFace()))
flags |= FXFONT_ITALIC;
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index beab7d87d3..bf52932a1d 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -80,20 +80,20 @@ bool ParserPageRangeString(CFX_ByteString rangstring,
int nLength = rangstring.GetLength();
CFX_ByteString cbCompareString("0123456789-,");
for (int i = 0; i < nLength; ++i) {
- if (cbCompareString.Find(rangstring[i]) == -1)
+ if (cbCompareString.Find(rangstring[i]) == FX_STRNPOS)
return false;
}
CFX_ByteString cbMidRange;
- int nStringFrom = 0;
- int nStringTo = 0;
+ FX_STRSIZE nStringFrom = 0;
+ FX_STRSIZE nStringTo = 0;
while (nStringTo < nLength) {
nStringTo = rangstring.Find(',', nStringFrom);
- if (nStringTo == -1)
+ if (nStringTo == FX_STRNPOS)
nStringTo = nLength;
cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom);
- int nMid = cbMidRange.Find('-');
- if (nMid == -1) {
+ FX_STRSIZE nMid = cbMidRange.Find('-');
+ if (nMid == FX_STRNPOS) {
long lPageNum = atol(cbMidRange.c_str());
if (lPageNum <= 0 || lPageNum > nCount)
return false;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 052bed55d2..7cccd2fb11 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -809,19 +809,19 @@ bool CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler,
void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent,
FPDF_DWORD& flag) {
- if (csSrcContent.Find(L" config ", 0) != -1)
+ if (csSrcContent.Find(L" config ", 0) != FX_STRNPOS)
flag |= FXFA_CONFIG;
- if (csSrcContent.Find(L" template ", 0) != -1)
+ if (csSrcContent.Find(L" template ", 0) != FX_STRNPOS)
flag |= FXFA_TEMPLATE;
- if (csSrcContent.Find(L" localeSet ", 0) != -1)
+ if (csSrcContent.Find(L" localeSet ", 0) != FX_STRNPOS)
flag |= FXFA_LOCALESET;
- if (csSrcContent.Find(L" datasets ", 0) != -1)
+ if (csSrcContent.Find(L" datasets ", 0) != FX_STRNPOS)
flag |= FXFA_DATASETS;
- if (csSrcContent.Find(L" xmpmeta ", 0) != -1)
+ if (csSrcContent.Find(L" xmpmeta ", 0) != FX_STRNPOS)
flag |= FXFA_XMPMETA;
- if (csSrcContent.Find(L" xfdf ", 0) != -1)
+ if (csSrcContent.Find(L" xfdf ", 0) != FX_STRNPOS)
flag |= FXFA_XFDF;
- if (csSrcContent.Find(L" form ", 0) != -1)
+ if (csSrcContent.Find(L" form ", 0) != FX_STRNPOS)
flag |= FXFA_FORM;
if (flag == 0) {
flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
@@ -840,11 +840,11 @@ bool CPDFXFA_DocEnvironment::MailToInfo(CFX_WideString& csURL,
if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0)
return false;
- int pos = srcURL.Find(L'?', 0);
+ FX_STRSIZE pos = srcURL.Find(L'?', 0);
CFX_WideString tmp;
- if (pos == -1) {
+ if (pos == FX_STRNPOS) {
pos = srcURL.Find(L'@', 0);
- if (pos == -1)
+ if (pos == FX_STRNPOS)
return false;
tmp = srcURL.Right(csURL.GetLength() - 7);
@@ -863,7 +863,7 @@ bool CPDFXFA_DocEnvironment::MailToInfo(CFX_WideString& csURL,
srcURL.TrimRight();
pos = srcURL.Find(L'&', 0);
- tmp = (pos == -1) ? srcURL : srcURL.Left(pos);
+ tmp = (pos == FX_STRNPOS) ? srcURL : srcURL.Left(pos);
tmp.TrimLeft();
tmp.TrimRight();
if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) {
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 06ed64c7cc..f5d3c68780 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -526,7 +526,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
CFX_WideString sFullMonths = fullmonths[m];
sFullMonths.MakeLower();
- if (sFullMonths.Find(sMonth.c_str(), 0) != -1) {
+ if (sFullMonths.Find(sMonth.c_str(), 0) != FX_STRNPOS) {
nMonth = m + 1;
i += 4;
j += nSkip;
@@ -932,7 +932,8 @@ bool CJS_PublicMethods::AFNumber_Keystroke(CJS_Runtime* pRuntime,
pEvent->SelEnd() - pEvent->SelStart());
}
- bool bHasSign = wstrValue.Find(L'-') != -1 && wstrSelected.Find(L'-') == -1;
+ bool bHasSign = wstrValue.Find(L'-') != FX_STRNPOS &&
+ wstrSelected.Find(L'-') == FX_STRNPOS;
if (bHasSign) {
// can't insert "change" in front to sign postion.
if (pEvent->SelStart() == 0) {
@@ -946,7 +947,7 @@ bool CJS_PublicMethods::AFNumber_Keystroke(CJS_Runtime* pRuntime,
iSepStyle = 0;
const wchar_t cSep = iSepStyle < 2 ? L'.' : L',';
- bool bHasSep = wstrValue.Find(cSep) != -1;
+ bool bHasSep = wstrValue.Find(cSep) != FX_STRNPOS;
for (FX_STRSIZE i = 0; i < wstrChange.GetLength(); ++i) {
if (wstrChange[i] == cSep) {
if (bHasSep) {
@@ -1111,7 +1112,7 @@ bool CJS_PublicMethods::AFDate_FormatEx(CJS_Runtime* pRuntime,
CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime);
double dDate = 0.0f;
- if (strValue.Find(L"GMT") != -1) {
+ if (strValue.Find(L"GMT") != FX_STRNPOS) {
// for GMT format time
// such as "Tue Aug 11 14:24:16 GMT+08002009"
dDate = MakeInterDate(strValue);