MCPcopy Create free account
hub / github.com/ElementsProject/elements / ParseInt32

Function ParseInt32

src/univalue/lib/univalue_get.cpp:31–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31bool ParseInt32(const std::string& str, int32_t *out)
32{
33 if (!ParsePrechecks(str))
34 return false;
35 char *endp = nullptr;
36 errno = 0; // strtol will not set errno if valid
37 long int n = strtol(str.c_str(), &endp, 10);
38 if(out) *out = (int32_t)n;
39 // Note that strtol returns a *long int*, so even if strtol doesn't report an over/underflow
40 // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
41 // platforms the size of these types may be different.
42 return endp && *endp == 0 && !errno &&
43 n >= std::numeric_limits<int32_t>::min() &&
44 n <= std::numeric_limits<int32_t>::max();
45}
46
47bool ParseInt64(const std::string& str, int64_t *out)
48{

Callers 1

get_intMethod · 0.70

Calls 1

ParsePrechecksFunction · 0.85

Tested by

no test coverage detected