]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix compiler warnings (-Wcast-function-type)
authorWolfgang Stöggl <c72578@yahoo.de>
Wed, 21 Aug 2019 15:50:09 +0000 (17:50 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Wed, 21 Aug 2019 17:26:54 +0000 (19:26 +0200)
- 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

index 806f635560e8111692a8207b6cc24ed47807656c..521aedaaf0d0288302e2b498b31d24ccf8672e70 100644 (file)
@@ -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;