From 53894390dba2ec571bab75157ebe60d11171ed07 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 9 Apr 2018 18:30:24 +0000 Subject: Use pdfium::span<> in CFX_BitStream, CPDF_SimpleParser. Get bounds checks in parsers automatically when using spans. Change-Id: I71fbe7b838435d455376db2f89817d807a9cdcfd Reviewed-on: https://pdfium-review.googlesource.com/29830 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- core/fpdfdoc/cpdf_defaultappearance.cpp | 4 ++-- core/fpdfdoc/cpdf_defaultappearance_unittest.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp index 4efb0655b4..de85c9cb33 100644 --- a/core/fpdfdoc/cpdf_defaultappearance.cpp +++ b/core/fpdfdoc/cpdf_defaultappearance.cpp @@ -59,7 +59,7 @@ Optional CPDF_DefaultAppearance::GetFont(float* fFontSize) { return {}; ByteString csFontNameTag; - CPDF_SimpleParser syntax(m_csDA.AsStringView()); + CPDF_SimpleParser syntax(m_csDA.AsStringView().span()); if (FindTagParamFromStart(&syntax, "Tf", 2)) { csFontNameTag = ByteString(syntax.GetWord()); csFontNameTag.Delete(0, 1); @@ -75,7 +75,7 @@ Optional CPDF_DefaultAppearance::GetColor(float fc[4]) { if (m_csDA.IsEmpty()) return {}; - CPDF_SimpleParser syntax(m_csDA.AsStringView()); + CPDF_SimpleParser syntax(m_csDA.AsStringView().span()); if (FindTagParamFromStart(&syntax, "g", 1)) { fc[0] = FX_atof(syntax.GetWord()); return {CFX_Color::kGray}; diff --git a/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp b/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp index 031fa8c89d..6f6c525052 100644 --- a/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp +++ b/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp @@ -6,6 +6,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" +#include "third_party/base/span.h" TEST(CPDFDefaultAppearanceTest, FindTagParamFromStart) { static const struct FindTagTestStruct { @@ -37,7 +38,7 @@ TEST(CPDFDefaultAppearanceTest, FindTagParamFromStart) { CPDF_DefaultAppearance da; for (size_t i = 0; i < FX_ArraySize(test_data); ++i) { CPDF_SimpleParser parser( - ByteStringView(test_data[i].input, test_data[i].input_size)); + pdfium::make_span(test_data[i].input, test_data[i].input_size)); EXPECT_EQ(test_data[i].result, da.FindTagParamFromStartForTesting(&parser, test_data[i].token, test_data[i].num_params)) -- cgit v1.2.3