Commit 6111a6a424324ed8d926852ed6ba22d4bf13fa62
1 parent
e7889ec5
Refactor QPDFTokenizer::inCharCode
Showing
2 changed files
with
12 additions
and
16 deletions
include/qpdf/QPDFTokenizer.hh
libqpdf/QPDFTokenizer.cc
| ... | ... | @@ -242,7 +242,6 @@ QPDFTokenizer::handleCharacter(char ch) |
| 242 | 242 | |
| 243 | 243 | case '(': |
| 244 | 244 | this->string_depth = 1; |
| 245 | - memset(this->bs_num_register, '\0', sizeof(this->bs_num_register)); | |
| 246 | 245 | this->state = st_in_string; |
| 247 | 246 | return; |
| 248 | 247 | |
| ... | ... | @@ -348,7 +347,7 @@ QPDFTokenizer::handleCharacter(char ch) |
| 348 | 347 | } |
| 349 | 348 | return; |
| 350 | 349 | |
| 351 | - case (st_in_string): | |
| 350 | + case st_in_string: | |
| 352 | 351 | inString(ch); |
| 353 | 352 | return; |
| 354 | 353 | |
| ... | ... | @@ -372,6 +371,8 @@ QPDFTokenizer::handleCharacter(char ch) |
| 372 | 371 | case '6': |
| 373 | 372 | case '7': |
| 374 | 373 | this->state = st_char_code; |
| 374 | + this->char_code = 0; | |
| 375 | + this->digit_count = 0; | |
| 375 | 376 | inCharCode(ch); |
| 376 | 377 | return; |
| 377 | 378 | |
| ... | ... | @@ -561,22 +562,17 @@ QPDFTokenizer::inString(char ch) |
| 561 | 562 | void |
| 562 | 563 | QPDFTokenizer::inCharCode(char ch) |
| 563 | 564 | { |
| 564 | - size_t bs_num_count = strlen(this->bs_num_register); | |
| 565 | - bool ch_is_octal = ('0' <= ch && ch <= '7'); | |
| 566 | - if ((bs_num_count == 3) || ((bs_num_count > 0) && (!ch_is_octal))) { | |
| 565 | + if (('0' <= ch) && (ch <= '7')) { | |
| 566 | + this->char_code = 8 * this->char_code + (int(ch) - int('0')); | |
| 567 | + if (++(this->digit_count) < 3) { | |
| 568 | + return; | |
| 569 | + } | |
| 567 | 570 | // We've accumulated \ddd. PDF Spec says to ignore |
| 568 | 571 | // high-order overflow. |
| 569 | - this->val += | |
| 570 | - static_cast<char>(strtol(this->bs_num_register, nullptr, 8)); | |
| 571 | - memset(this->bs_num_register, '\0', sizeof(this->bs_num_register)); | |
| 572 | - bs_num_count = 0; | |
| 573 | - this->state = st_in_string; | |
| 574 | - inString(ch); | |
| 575 | - return; | |
| 576 | - } else if (ch_is_octal) { | |
| 577 | - this->bs_num_register[bs_num_count++] = ch; | |
| 578 | - return; | |
| 579 | 572 | } |
| 573 | + this->val += char(this->char_code % 256); | |
| 574 | + this->state = st_in_string; | |
| 575 | + return; | |
| 580 | 576 | } |
| 581 | 577 | |
| 582 | 578 | void | ... | ... |