MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_to_u64

Function json_to_u64

common/json_parse_simple.c:62–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61
62bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
63{
64 char *end;
65 unsigned long long l;
66
67 errno = 0;
68 /* Decimal only, as for json_to_s64 below; and strtoull would
69 * happily negate a leading '-', which is not an unsigned number. */
70 if (tok->start == tok->end || buffer[tok->start] == '-')
71 return false;
72 l = strtoull(buffer + tok->start, &end, 10);
73 if (end != buffer + tok->end)
74 return false;
75
76 BUILD_ASSERT(sizeof(l) >= sizeof(*num));
77 *num = l;
78
79 /* Check for overflow */
80 if (l == ULLONG_MAX && errno == ERANGE)
81 return false;
82
83 if (*num != l)
84 return false;
85
86 return true;
87}
88
89bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num)
90{

Callers 1

json_to_u32Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected