2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-10 18:24:40 +00:00

Avoid shrinking QPDFTokenizer::val and QPDFTokenizer::raw_val

This commit is contained in:
m-holger 2022-08-20 19:43:00 +01:00
parent 45a6100cbb
commit cf945eeabf

View File

@ -78,8 +78,8 @@ QPDFTokenizer::reset()
{ {
state = st_top; state = st_top;
type = tt_bad; type = tt_bad;
val = ""; val.clear();
raw_val = ""; raw_val.clear();
error_message = ""; error_message = "";
unread_char = false; unread_char = false;
char_to_unread = '\0'; char_to_unread = '\0';
@ -175,7 +175,8 @@ QPDFTokenizer::resolveLiteral()
nval.append(1, ch); nval.append(1, ch);
} }
} }
this->val = nval; this->val.clear();
this->val += nval;
} else if (QUtil::is_number(this->val.c_str())) { } else if (QUtil::is_number(this->val.c_str())) {
if (this->val.find('.') != std::string::npos) { if (this->val.find('.') != std::string::npos) {
this->type = tt_real; this->type = tt_real;
@ -282,7 +283,7 @@ QPDFTokenizer::presentCharacter(char ch)
} }
} else if (this->state == st_lt) { } else if (this->state == st_lt) {
if (ch == '<') { if (ch == '<') {
this->val = "<<"; this->val += "<<";
this->type = tt_dict_open; this->type = tt_dict_open;
this->state = st_token_ready; this->state = st_token_ready;
} else { } else {
@ -291,11 +292,11 @@ QPDFTokenizer::presentCharacter(char ch)
} }
} else if (this->state == st_gt) { } else if (this->state == st_gt) {
if (ch == '>') { if (ch == '>') {
this->val = ">>"; this->val += ">>";
this->type = tt_dict_close; this->type = tt_dict_close;
this->state = st_token_ready; this->state = st_token_ready;
} else { } else {
this->val = ">"; this->val += ">";
this->type = tt_bad; this->type = tt_bad;
QTC::TC("qpdf", "QPDFTokenizer bad >"); QTC::TC("qpdf", "QPDFTokenizer bad >");
this->error_message = "unexpected >"; this->error_message = "unexpected >";
@ -437,7 +438,8 @@ QPDFTokenizer::presentCharacter(char ch)
char nch = static_cast<char>(strtol(num, nullptr, 16)); char nch = static_cast<char>(strtol(num, nullptr, 16));
nval += nch; nval += nch;
} }
this->val = nval; this->val.clear();
this->val += nval;
} else if (QUtil::is_hex_digit(ch)) { } else if (QUtil::is_hex_digit(ch)) {
this->val += ch; this->val += ch;
} else if (isSpace(ch)) { } else if (isSpace(ch)) {
@ -600,7 +602,8 @@ QPDFTokenizer::getToken(Token& token, bool& unread_char, char& ch)
ch = this->char_to_unread; ch = this->char_to_unread;
if (ready) { if (ready) {
if (this->type == tt_bad) { if (this->type == tt_bad) {
this->val = this->raw_val; this->val.clear();
this->val += this->raw_val;
} }
token = token =
Token(this->type, this->val, this->raw_val, this->error_message); Token(this->type, this->val, this->raw_val, this->error_message);