aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-20 13:41:38 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-20 13:43:59 +0200
commit289193dd1a5dea186e33e9ce1a5493c7f39e6b71 (patch)
treee30ec8e26951f4b400affb66e035741240096fd6
parent405848deebcb2709865c9f57b8f1b85da217e86d (diff)
downloadxK-289193dd1a5dea186e33e9ce1a5493c7f39e6b71.tar.gz
xK-289193dd1a5dea186e33e9ce1a5493c7f39e6b71.tar.xz
xK-289193dd1a5dea186e33e9ce1a5493c7f39e6b71.zip
kike: silence an annoying build warning
-rw-r--r--kike.c35
1 files 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 ();