From a2c2a9d2a1e718e08bb90f92a2f24f4cb990189f Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 27 Jun 2018 21:14:22 +0000 Subject: Add fxcrt::AutoRestorer::AbandonRestoration(). Kinda like reaching a commit point, makes going forward more useful. Change-Id: I7695b6e627d4cd8ed2bccb667d0cabd7f42c7b1c Reviewed-on: https://pdfium-review.googlesource.com/35970 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/parser/cpdf_syntax_parser.cpp | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp index 3cce446aae..0910a39e2a 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp @@ -359,7 +359,7 @@ std::unique_ptr CPDF_SyntaxParser::GetObjectBody( std::unique_ptr CPDF_SyntaxParser::GetObjectBodyInternal( CPDF_IndirectObjectHolder* pObjList, ParseType parse_type) { - AutoRestorer restorer(&s_CurrentRecursionDepth); + AutoRestorer depth_restorer(&s_CurrentRecursionDepth); if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) return nullptr; @@ -370,19 +370,21 @@ std::unique_ptr CPDF_SyntaxParser::GetObjectBodyInternal( return nullptr; if (bIsNumber) { - FX_FILESIZE SavedPos = m_Pos; + AutoRestorer pos_restorer(&m_Pos); ByteString nextword = GetNextWord(&bIsNumber); - if (bIsNumber) { - ByteString nextword2 = GetNextWord(nullptr); - if (nextword2 == "R") { - uint32_t refnum = FXSYS_atoui(word.c_str()); - if (refnum == CPDF_Object::kInvalidObjNum) - return nullptr; - return pdfium::MakeUnique(pObjList, refnum); - } - } - m_Pos = SavedPos; - return pdfium::MakeUnique(word.AsStringView()); + if (!bIsNumber) + return pdfium::MakeUnique(word.AsStringView()); + + ByteString nextword2 = GetNextWord(nullptr); + if (nextword2 != "R") + return pdfium::MakeUnique(word.AsStringView()); + + pos_restorer.AbandonRestoration(); + uint32_t refnum = FXSYS_atoui(word.c_str()); + if (refnum == CPDF_Object::kInvalidObjNum) + return nullptr; + + return pdfium::MakeUnique(pObjList, refnum); } if (word == "true" || word == "false") @@ -453,12 +455,10 @@ std::unique_ptr CPDF_SyntaxParser::GetObjectBodyInternal( } } - FX_FILESIZE SavedPos = m_Pos; - ByteString nextword = GetNextWord(nullptr); - if (nextword != "stream") { - m_Pos = SavedPos; + AutoRestorer pos_restorer(&m_Pos); + if (GetNextWord(nullptr) != "stream") return std::move(pDict); - } + pos_restorer.AbandonRestoration(); return ReadStream(std::move(pDict)); } if (word == ">>") -- cgit v1.2.3