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

Function ParseUInt32

src/utilstrencodings.cpp:307–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307bool ParseUInt32(const std::string& str, uint32_t *out)
308{
309 if (!ParsePrechecks(str))
310 return false;
311 if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoul accepts these by default if they fit in the range
312 return false;
313 char *endp = nullptr;
314 errno = 0; // strtoul will not set errno if valid
315 unsigned long int n = strtoul(str.c_str(), &endp, 10);
316 if(out) *out = (uint32_t)n;
317 // Note that strtoul returns a *unsigned long int*, so even if it doesn't report an over/underflow
318 // we still have to check that the returned value is within the range of an *uint32_t*. On 64-bit
319 // platforms the size of these types may be different.
320 return endp && *endp == 0 && !errno &&
321 n <= std::numeric_limits<uint32_t>::max();
322}
323
324bool ParseUInt64(const std::string& str, uint64_t *out)
325{

Callers 4

ParseHDKeypathFunction · 0.85
ParseKeyPathFunction · 0.85
ParseScriptFunction · 0.85
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