From 10fda01b07a29bb2e1dec9a51bb6197bc7aa72bf Mon Sep 17 00:00:00 2001 From: m-holger Date: Wed, 24 Aug 2022 00:36:24 +0100 Subject: In QPDFTokenizer::readToken move call to getToken out of loop --- libqpdf/QPDFTokenizer.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index 6e492f2b..9f45a374 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -975,25 +975,21 @@ QPDFTokenizer::readToken( size_t max_len) { qpdf_offset_t offset = input->tell(); - Token token; - bool unread_char; - char char_to_unread; - bool presented_eof = false; - while (!getToken(token, unread_char, char_to_unread)) { + + while (this->state != st_token_ready) { char ch; if (input->read(&ch, 1) == 0) { - if (!presented_eof) { - presentEOF(); - presented_eof = true; - if ((this->type == tt_eof) && (!this->allow_eof)) { - // Nothing in the qpdf library calls readToken - // without allowEOF anymore, so this case is not - // exercised. - this->type = tt_bad; - this->error_message = "unexpected EOF"; - offset = input->getLastOffset(); - } - } else { + presentEOF(); + + if ((this->type == tt_eof) && (!this->allow_eof)) { + // Nothing in the qpdf library calls readToken + // without allowEOF anymore, so this case is not + // exercised. + this->type = tt_bad; + this->error_message = "unexpected EOF"; + offset = input->getLastOffset(); + } + if (this->state != st_token_ready) { throw std::logic_error( "getToken returned false after presenting EOF"); } @@ -1014,6 +1010,10 @@ QPDFTokenizer::readToken( } } + Token token; + bool unread_char; + char char_to_unread; + getToken(token, unread_char, char_to_unread); if (unread_char) { input->unreadCh(char_to_unread); } -- cgit v1.2.3-54-g00ecf