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

Function json_to_s64

common/json_parse_simple.c:89–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num)
90{
91 char *end;
92 long long l;
93
94 errno = 0;
95 /* From json.org: "A number is very much like a C or Java number,
96 * except that the octal and hexadecimal formats are not used." */
97 l = strtoll(buffer + tok->start, &end, 10);
98 if (tok->start == tok->end || end != buffer + tok->end)
99 return false;
100
101 BUILD_ASSERT(sizeof(l) >= sizeof(*num));
102 *num = l;
103
104 /* Check for overflow/underflow */
105 if ((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE)
106 return false;
107
108 /* Check if the number did not fit in `s64` (in case `long long`
109 is a bigger type). */
110 if (*num != l)
111 return false;
112
113 return true;
114}
115
116bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num)
117{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected