Commit 10fda01b07a29bb2e1dec9a51bb6197bc7aa72bf

Authored by m-holger
1 parent e4073ee8

In QPDFTokenizer::readToken move call to getToken out of loop

Showing 1 changed file with 17 additions and 17 deletions
libqpdf/QPDFTokenizer.cc
@@ -975,25 +975,21 @@ QPDFTokenizer::readToken( @@ -975,25 +975,21 @@ QPDFTokenizer::readToken(
975 size_t max_len) 975 size_t max_len)
976 { 976 {
977 qpdf_offset_t offset = input->tell(); 977 qpdf_offset_t offset = input->tell();
978 - Token token;  
979 - bool unread_char;  
980 - char char_to_unread;  
981 - bool presented_eof = false;  
982 - while (!getToken(token, unread_char, char_to_unread)) { 978 +
  979 + while (this->state != st_token_ready) {
983 char ch; 980 char ch;
984 if (input->read(&ch, 1) == 0) { 981 if (input->read(&ch, 1) == 0) {
985 - if (!presented_eof) {  
986 - presentEOF();  
987 - presented_eof = true;  
988 - if ((this->type == tt_eof) && (!this->allow_eof)) {  
989 - // Nothing in the qpdf library calls readToken  
990 - // without allowEOF anymore, so this case is not  
991 - // exercised.  
992 - this->type = tt_bad;  
993 - this->error_message = "unexpected EOF";  
994 - offset = input->getLastOffset();  
995 - }  
996 - } else { 982 + presentEOF();
  983 +
  984 + if ((this->type == tt_eof) && (!this->allow_eof)) {
  985 + // Nothing in the qpdf library calls readToken
  986 + // without allowEOF anymore, so this case is not
  987 + // exercised.
  988 + this->type = tt_bad;
  989 + this->error_message = "unexpected EOF";
  990 + offset = input->getLastOffset();
  991 + }
  992 + if (this->state != st_token_ready) {
997 throw std::logic_error( 993 throw std::logic_error(
998 "getToken returned false after presenting EOF"); 994 "getToken returned false after presenting EOF");
999 } 995 }
@@ -1014,6 +1010,10 @@ QPDFTokenizer::readToken( @@ -1014,6 +1010,10 @@ QPDFTokenizer::readToken(
1014 } 1010 }
1015 } 1011 }
1016 1012
  1013 + Token token;
  1014 + bool unread_char;
  1015 + char char_to_unread;
  1016 + getToken(token, unread_char, char_to_unread);
1017 if (unread_char) { 1017 if (unread_char) {
1018 input->unreadCh(char_to_unread); 1018 input->unreadCh(char_to_unread);
1019 } 1019 }