Commit 6111a6a424324ed8d926852ed6ba22d4bf13fa62
1 parent
e7889ec5
Refactor QPDFTokenizer::inCharCode
Showing
2 changed files
with
12 additions
and
16 deletions
include/qpdf/QPDFTokenizer.hh
| @@ -241,7 +241,7 @@ class QPDFTokenizer | @@ -241,7 +241,7 @@ class QPDFTokenizer | ||
| 241 | // State for strings | 241 | // State for strings |
| 242 | int string_depth; | 242 | int string_depth; |
| 243 | int char_code; | 243 | int char_code; |
| 244 | - char bs_num_register[4]; | 244 | + int digit_count; |
| 245 | }; | 245 | }; |
| 246 | 246 | ||
| 247 | #endif // QPDFTOKENIZER_HH | 247 | #endif // QPDFTOKENIZER_HH |
libqpdf/QPDFTokenizer.cc
| @@ -242,7 +242,6 @@ QPDFTokenizer::handleCharacter(char ch) | @@ -242,7 +242,6 @@ QPDFTokenizer::handleCharacter(char ch) | ||
| 242 | 242 | ||
| 243 | case '(': | 243 | case '(': |
| 244 | this->string_depth = 1; | 244 | this->string_depth = 1; |
| 245 | - memset(this->bs_num_register, '\0', sizeof(this->bs_num_register)); | ||
| 246 | this->state = st_in_string; | 245 | this->state = st_in_string; |
| 247 | return; | 246 | return; |
| 248 | 247 | ||
| @@ -348,7 +347,7 @@ QPDFTokenizer::handleCharacter(char ch) | @@ -348,7 +347,7 @@ QPDFTokenizer::handleCharacter(char ch) | ||
| 348 | } | 347 | } |
| 349 | return; | 348 | return; |
| 350 | 349 | ||
| 351 | - case (st_in_string): | 350 | + case st_in_string: |
| 352 | inString(ch); | 351 | inString(ch); |
| 353 | return; | 352 | return; |
| 354 | 353 | ||
| @@ -372,6 +371,8 @@ QPDFTokenizer::handleCharacter(char ch) | @@ -372,6 +371,8 @@ QPDFTokenizer::handleCharacter(char ch) | ||
| 372 | case '6': | 371 | case '6': |
| 373 | case '7': | 372 | case '7': |
| 374 | this->state = st_char_code; | 373 | this->state = st_char_code; |
| 374 | + this->char_code = 0; | ||
| 375 | + this->digit_count = 0; | ||
| 375 | inCharCode(ch); | 376 | inCharCode(ch); |
| 376 | return; | 377 | return; |
| 377 | 378 | ||
| @@ -561,22 +562,17 @@ QPDFTokenizer::inString(char ch) | @@ -561,22 +562,17 @@ QPDFTokenizer::inString(char ch) | ||
| 561 | void | 562 | void |
| 562 | QPDFTokenizer::inCharCode(char ch) | 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 | // We've accumulated \ddd. PDF Spec says to ignore | 570 | // We've accumulated \ddd. PDF Spec says to ignore |
| 568 | // high-order overflow. | 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 | void | 578 | void |