finds the end of an integer and verifies that it looks valid this does not detect all overflows, just the ones that are an order of magnitude beyond. Exact overflow checking is done when the integer value is queried from a bdecode_node.
| 64 | // beyond. Exact overflow checking is done when the integer value is queried |
| 65 | // from a bdecode_node. |
| 66 | char const* check_integer(char const* start, char const* end |
| 67 | , bdecode_errors::error_code_enum& e) |
| 68 | { |
| 69 | if (start == end) |
| 70 | { |
| 71 | e = bdecode_errors::unexpected_eof; |
| 72 | return start; |
| 73 | } |
| 74 | |
| 75 | if (*start == '-') |
| 76 | { |
| 77 | ++start; |
| 78 | if (start == end) |
| 79 | { |
| 80 | e = bdecode_errors::unexpected_eof; |
| 81 | return start; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | int digits = 0; |
| 86 | do |
| 87 | { |
| 88 | if (!numeric(*start)) |
| 89 | { |
| 90 | e = bdecode_errors::expected_digit; |
| 91 | break; |
| 92 | } |
| 93 | ++start; |
| 94 | ++digits; |
| 95 | |
| 96 | if (start == end) |
| 97 | { |
| 98 | e = bdecode_errors::unexpected_eof; |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | while (*start != 'e'); |
| 103 | |
| 104 | if (digits > 20) |
| 105 | { |
| 106 | e = bdecode_errors::overflow; |
| 107 | } |
| 108 | |
| 109 | return start; |
| 110 | } |
| 111 | |
| 112 | struct stack_frame |
| 113 | { |