From: Wolfgang Stöggl Date: Wed, 21 Aug 2019 15:50:09 +0000 (+0200) Subject: Fix compiler warnings (-Wcast-function-type) X-Git-Tag: v1.8.0~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9421c2fa0fa17a4b339f1ca153be1b85d362ac7;p=thirdparty%2Frrdtool-1.x.git Fix compiler warnings (-Wcast-function-type) - Add tree_compare_func() and use this function instead of `(GCompareDataFunc) strcmp` Fixes the following gcc compiler warning: rrd_daemon.c:4245:34: warning: cast between incompatible function types from ‘int (*)(const char *, const char *)’ to ‘gint (*)(const void *, const void *, void *)’ {aka ‘int (*)(const void *, const void *, void *)’} [-Wcast-function-type] cache_tree = g_tree_new_full((GCompareDataFunc) strcmp, NULL, NULL, - Use g_strcmp0() instead of strcmp() in tree_compare_func(). g_strcmp0() compares str1 and str2 like strcmp(). Handles NULL gracefully by sorting it before non-NULL strings. Comparing two NULL pointers returns 0. - Cast free_cache_item using (void (*)(void) Fixes the following gcc compiler warning: rrd_daemon.c:4246:34: warning: cast between incompatible function types from ‘void * (*)(cache_item_t *)’ {aka ‘void * (*)(struct cache_item_s *)’} to ‘void (*)(void *)’ [-Wcast-function-type] (GDestroyNotify) free_cache_item); --- diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 806f6355..521aedaa 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -4181,6 +4181,19 @@ static void *listen_thread_main( return (NULL); } /* }}} void *listen_thread_main */ +/* `tree_compare_func()` is used instead of `(GCompareDataFunc) strcmp` to avoid gcc compiler warning: + * cast between incompatible function types from ‘int (*)(const char *, const char *)’ to ‘gint (*)(const void *, const void *, void *)’ + * {aka ‘int (*)(const void *, const void *, void *)’} [-Wcast-function-type] + */ +static gint tree_compare_func( + gconstpointer a, + gconstpointer b, + gpointer user_data) +{ + (void) user_data; /* Silence -Wunused-parameter warning */ + return g_strcmp0(a, b); +} + static int daemonize( void) { /* {{{ */ @@ -4242,8 +4255,9 @@ static int daemonize( openlog("rrdcached", LOG_PID, LOG_DAEMON); RRDD_LOG(LOG_INFO, "starting up"); - cache_tree = g_tree_new_full((GCompareDataFunc) strcmp, NULL, NULL, - (GDestroyNotify) free_cache_item); + cache_tree = g_tree_new_full(tree_compare_func, NULL, NULL, + (GDestroyNotify) (void (*)(void)) + free_cache_item); if (cache_tree == NULL) { RRDD_LOG(LOG_ERR, "daemonize: g_tree_new failed."); goto error;