MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / ParseUInt64

Function ParseUInt64

src/utilstrencodings.cpp:324–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324bool ParseUInt64(const std::string& str, uint64_t *out)
325{
326 if (!ParsePrechecks(str))
327 return false;
328 if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoull accepts these by default if they fit in the range
329 return false;
330 char *endp = nullptr;
331 errno = 0; // strtoull will not set errno if valid
332 unsigned long long int n = strtoull(str.c_str(), &endp, 10);
333 if(out) *out = (uint64_t)n;
334 // Note that strtoull returns a *unsigned long long int*, so even if it doesn't report an over/underflow
335 // we still have to check that the returned value is within the range of an *uint64_t*.
336 return endp && *endp == 0 && !errno &&
337 n <= std::numeric_limits<uint64_t>::max();
338}
339
340
341bool ParseDouble(const std::string& str, double *out)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 3

maxFunction · 0.85
ParsePrechecksFunction · 0.70
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68