| 79 | } |
| 80 | |
| 81 | bool LegacyParseUInt32(const std::string& str, uint32_t* out) |
| 82 | { |
| 83 | if (!LegacyParsePrechecks(str)) |
| 84 | return false; |
| 85 | if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoul accepts these by default if they fit in the range |
| 86 | return false; |
| 87 | char* endp = nullptr; |
| 88 | errno = 0; // strtoul will not set errno if valid |
| 89 | unsigned long int n = strtoul(str.c_str(), &endp, 10); |
| 90 | if (out) *out = (uint32_t)n; |
| 91 | // Note that strtoul returns a *unsigned long int*, so even if it doesn't report an over/underflow |
| 92 | // we still have to check that the returned value is within the range of an *uint32_t*. On 64-bit |
| 93 | // platforms the size of these types may be different. |
| 94 | return endp && *endp == 0 && !errno && |
| 95 | n <= std::numeric_limits<uint32_t>::max(); |
| 96 | } |
| 97 | |
| 98 | bool LegacyParseUInt8(const std::string& str, uint8_t* out) |
| 99 | { |
no test coverage detected