| 290 | } |
| 291 | |
| 292 | bool ParseInt64(const std::string& str, int64_t *out) |
| 293 | { |
| 294 | if (!ParsePrechecks(str)) |
| 295 | return false; |
| 296 | char *endp = nullptr; |
| 297 | errno = 0; // strtoll will not set errno if valid |
| 298 | long long int n = strtoll(str.c_str(), &endp, 10); |
| 299 | if(out) *out = (int64_t)n; |
| 300 | // Note that strtoll returns a *long long int*, so even if strtol doesn't report an over/underflow |
| 301 | // we still have to check that the returned value is within the range of an *int64_t*. |
| 302 | return endp && *endp == 0 && !errno && |
| 303 | n >= std::numeric_limits<int64_t>::min() && |
| 304 | n <= std::numeric_limits<int64_t>::max(); |
| 305 | } |
| 306 | |
| 307 | bool ParseUInt32(const std::string& str, uint32_t *out) |
| 308 | { |
no test coverage detected