From 289193dd1a5dea186e33e9ce1a5493c7f39e6b71 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 20 Sep 2020 13:41:38 +0200 Subject: kike: silence an annoying build warning --- kike.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/kike.c b/kike.c index b886427..1708d2c 100644 --- a/kike.c +++ b/kike.c @@ -3680,26 +3680,35 @@ irc_initialize_motd (struct server_context *ctx, struct error **e) return true; } +static bool +irc_parse_config_unsigned (const char *name, const char *value, unsigned *out, + unsigned long min, unsigned long max, struct error **e) +{ + unsigned long ul; + hard_assert (value != NULL); + if (!xstrtoul (&ul, value, 10) || ul > max || ul < min) + { + error_set (e, "invalid configuration value for `%s': %s", + name, "the number is invalid or out of range"); + return false; + } + *out = ul; + return true; +} + /// This function handles values that require validation before their first use, /// or some kind of a transformation (such as conversion to an integer) needs /// to be done before they can be used directly. static bool irc_parse_config (struct server_context *ctx, struct error **e) { - unsigned long ul; #define PARSE_UNSIGNED(name, min, max) \ - const char *name = str_map_find (&ctx->config, #name); \ - hard_assert (name != NULL); \ - if (!xstrtoul (&ul, name, 10) || ul > max || ul < min) \ - { \ - error_set (e, "invalid configuration value for `%s': %s", \ - #name, "the number is invalid or out of range"); \ - return false; \ - } \ - ctx->name = ul - - PARSE_UNSIGNED (ping_interval, 1, UINT_MAX); - PARSE_UNSIGNED (max_connections, 0, UINT_MAX); + irc_parse_config_unsigned (#name, str_map_find (&ctx->config, #name), \ + &ctx->name, min, max, e) + + if (!PARSE_UNSIGNED (ping_interval, 1, UINT_MAX) + || !PARSE_UNSIGNED (max_connections, 0, UINT_MAX)) + return false; bool result = true; struct strv fingerprints = strv_make (); -- cgit v1.2.3-70-g09d2