summaryrefslogtreecommitdiff
path: root/core/fpdfapi
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 /core/fpdfapi
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 'core/fpdfapi')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp4
3 files changed, 9 insertions, 6 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 62b10c9149..e9676b1115 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -186,8 +186,10 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessStandardText) {
std::ostringstream buf;
TestProcessText(&generator, &buf, pTextObj.get());
CFX_ByteString textString(buf);
- int firstResourceAt = textString.Find('/') + 1;
- int secondResourceAt = textString.ReverseFind('/') + 1;
+ FX_STRSIZE firstResourceAt = textString.Find('/') + 1;
+ FX_STRSIZE secondResourceAt = textString.ReverseFind('/') + 1;
+ EXPECT_NE(FX_STRNPOS, firstResourceAt);
+ EXPECT_NE(FX_STRNPOS, secondResourceAt);
CFX_ByteString firstString = textString.Left(firstResourceAt);
CFX_ByteString midString =
textString.Mid(firstResourceAt, secondResourceAt - firstResourceAt);
@@ -252,7 +254,8 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) {
}
CFX_ByteString textString(buf);
- int firstResourceAt = textString.Find('/') + 1;
+ FX_STRSIZE firstResourceAt = textString.Find('/') + 1;
+ EXPECT_NE(FX_STRNPOS, firstResourceAt);
CFX_ByteString firstString = textString.Left(firstResourceAt);
CFX_ByteString lastString =
textString.Right(textString.GetLength() - firstResourceAt);
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 288f9d57a8..692de0f5eb 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -316,7 +316,7 @@ void CPDF_StreamContentParser::AddNameParam(const CFX_ByteStringC& bsName) {
m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName));
} else {
param.m_Type = ContentParam::NAME;
- if (bsName.Find('#') == -1) {
+ if (bsName.Find('#') == FX_STRNPOS) {
memcpy(param.m_Name.m_Buffer, bsName.raw_str(), bsName.GetLength());
param.m_Name.m_Len = bsName.GetLength();
} else {
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index 0cd4ca9225..7025b3e7d8 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -89,7 +89,7 @@ int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteString& key) {
}
CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
- if (bstr.Find('#') == -1)
+ if (bstr.Find('#') == FX_STRNPOS)
return CFX_ByteString(bstr);
int size = bstr.GetLength();
@@ -110,7 +110,7 @@ CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
}
CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) {
- if (orig.Find('#') == -1)
+ if (orig.Find('#') == FX_STRNPOS)
return orig;
return PDF_NameDecode(orig.AsStringC());
}