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

Function LegacyParseUInt32

src/test/fuzz/string.cpp:81–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81bool LegacyParseUInt32(const std::string& str, uint32_t* out)
82{
83 if (!LegacyParsePrechecks(str))
84 return false;
85 if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoul accepts these by default if they fit in the range
86 return false;
87 char* endp = nullptr;
88 errno = 0; // strtoul will not set errno if valid
89 unsigned long int n = strtoul(str.c_str(), &endp, 10);
90 if (out) *out = (uint32_t)n;
91 // Note that strtoul returns a *unsigned long int*, so even if it doesn't report an over/underflow
92 // we still have to check that the returned value is within the range of an *uint32_t*. On 64-bit
93 // platforms the size of these types may be different.
94 return endp && *endp == 0 && !errno &&
95 n <= std::numeric_limits<uint32_t>::max();
96}
97
98bool LegacyParseUInt8(const std::string& str, uint8_t* out)
99{

Callers 2

LegacyParseUInt8Function · 0.85
FUZZ_TARGETFunction · 0.85

Calls 2

LegacyParsePrechecksFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected