mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
signed types: add handlers for signed types
We're adding signed types to the spec! This adds the support mechanisms for them.
This commit is contained in:
committed by
Rusty Russell
parent
ad592d8b0d
commit
aba4d18ed1
@@ -23,30 +23,6 @@
|
||||
#include <stdio.h>
|
||||
#include <wire/onion_wire.h>
|
||||
|
||||
bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num)
|
||||
{
|
||||
char *end;
|
||||
long long l;
|
||||
|
||||
l = strtoll(buffer + tok->start, &end, 0);
|
||||
if (end != buffer + tok->end)
|
||||
return false;
|
||||
|
||||
BUILD_ASSERT(sizeof(l) >= sizeof(*num));
|
||||
*num = l;
|
||||
|
||||
/* Check for overflow/underflow */
|
||||
if ((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE)
|
||||
return false;
|
||||
|
||||
/* Check if the number did not fit in `s64` (in case `long long`
|
||||
is a bigger type). */
|
||||
if (*num != l)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool json_to_millionths(const char *buffer, const jsmntok_t *tok,
|
||||
u64 *millionths)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user