kike: silence an annoying build warning

This commit is contained in:
Přemysl Eric Janouch 2020-09-20 13:41:38 +02:00
parent 405848deeb
commit 289193dd1a
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 21 additions and 12 deletions

33
kike.c
View File

@ -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 ();