From a9421c2fa0fa17a4b339f1ca153be1b85d362ac7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wolfgang=20St=C3=B6ggl?= Date: Wed, 21 Aug 2019 17:50:09 +0200 Subject: [PATCH] Fix compiler warnings (-Wcast-function-type) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - 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); --- src/rrd_daemon.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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; -- 2.47.3