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

Function LegacyParseInt32

src/test/fuzz/string.cpp:50–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50bool LegacyParseInt32(const std::string& str, int32_t* out)
51{
52 if (!LegacyParsePrechecks(str))
53 return false;
54 char* endp = nullptr;
55 errno = 0; // strtol will not set errno if valid
56 long int n = strtol(str.c_str(), &endp, 10);
57 if (out) *out = (int32_t)n;
58 // Note that strtol returns a *long int*, so even if strtol doesn't report an over/underflow
59 // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
60 // platforms the size of these types may be different.
61 return endp && *endp == 0 && !errno &&
62 n >= std::numeric_limits<int32_t>::min() &&
63 n <= std::numeric_limits<int32_t>::max();
64}
65
66bool LegacyParseInt64(const std::string& str, int64_t* out)
67{

Callers 1

FUZZ_TARGETFunction · 0.85

Calls 1

LegacyParsePrechecksFunction · 0.85

Tested by

no test coverage detected