From c934fe095b0ad1ef4e7557bb87fa8ed3beba78a9 Mon Sep 17 00:00:00 2001 From: niftynei Date: Sat, 29 May 2021 13:56:03 -0500 Subject: [PATCH] libplugin: add u16_option parsing A couple of the fields for liquidity_ads are u16 --- plugins/libplugin.c | 19 +++++++++++++++++++ plugins/libplugin.h | 1 + 2 files changed, 20 insertions(+) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index f1ef5b653..43216f335 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -925,6 +925,25 @@ char *u32_option(const char *arg, u32 *i) return NULL; } +char *u16_option(const char *arg, u16 *i) +{ + char *endp; + u64 n; + + errno = 0; + n = strtoul(arg, &endp, 0); + if (*endp || !arg[0]) + return tal_fmt(NULL, "'%s' is not a number", arg); + if (errno) + return tal_fmt(NULL, "'%s' is out of range", arg); + + *i = n; + if (*i != n) + return tal_fmt(NULL, "'%s' is too large (overflow)", arg); + + return NULL; +} + char *bool_option(const char *arg, bool *i) { if (!streq(arg, "true") && !streq(arg, "false")) diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 6ae600fd9..e480ed50d 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -277,6 +277,7 @@ void plugin_notify_progress(struct command *cmd, /* Standard helpers */ char *u64_option(const char *arg, u64 *i); char *u32_option(const char *arg, u32 *i); +char *u16_option(const char *arg, u16 *i); char *bool_option(const char *arg, bool *i); char *charp_option(const char *arg, char **p); char *flag_option(const char *arg, bool *i);