From 289193dd1a5dea186e33e9ce1a5493c7f39e6b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sun, 20 Sep 2020 13:41:38 +0200 Subject: [PATCH] kike: silence an annoying build warning --- kike.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 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 + irc_parse_config_unsigned (#name, str_map_find (&ctx->config, #name), \ + &ctx->name, min, max, e) - PARSE_UNSIGNED (ping_interval, 1, UINT_MAX); - PARSE_UNSIGNED (max_connections, 0, UINT_MAX); + 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 ();