cli: use return value of g_string_free
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 3 Apr 2023 01:09:56 +0000 (21:09 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 3 Apr 2023 16:47:10 +0000 (12:47 -0400)
When building against glib 2.76, I see:

      CC       babeltrace2-cfg-cli-args.o
    In file included from /usr/include/glib-2.0/glib/giochannel.h:36,
                     from /usr/include/glib-2.0/glib.h:56,
                     from /home/simark/src/babeltrace/src/common/assert.h:12,
                     from /home/simark/src/babeltrace/src/logging/log.h:27,
                     from /home/simark/src/babeltrace/src/cli/logging.h:11,
                     from /home/simark/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:10:
    /home/simark/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c: In function ‘plugin_comp_cls_names’:
    /usr/include/glib-2.0/glib/gstring.h:72:5: error: ignoring return value of ‘g_string_free_and_steal’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
       68 |   (__builtin_constant_p (free_segment) ?        \
          |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       69 |     ((free_segment) ?                           \
          |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       70 |       (g_string_free) ((str), (free_segment)) : \
          |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       71 |       g_string_free_and_steal (str))            \
          |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       72 |     :                                           \
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       73 |     (g_string_free) ((str), (free_segment)))
          |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:136:25: note: in expansion of macro ‘g_string_free’
      136 |                         g_string_free(gs_name, FALSE);
          |                         ^~~~~~~~~~~~~

glib made g_string_free warn about unused results in this commit:

  https://gitlab.gnome.org/GNOME/glib/-/commit/c3d07a625a407b56432f4b8c60295fd32ee1ee2b

Fix that by changing our code to get the released value from the return
value of g_string_free, rather than doing it in two steps..  No
functional changes intended.

Change-Id: I62f4002d0487165b7c9d33f471937185f3bc0f82
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9728
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cli/babeltrace2-cfg-cli-args.c

index 6c187b4f12df7a7b0c2a7b2b88d231138d4c4f2b..a0da0ddf52d43e268806003813f856c8678bd9c5 100644 (file)
@@ -132,17 +132,14 @@ void plugin_comp_cls_names(const char *arg, char **name, char **plugin,
                        *name = NULL;
                        g_string_free(gs_name, TRUE);
                } else {
-                       *name = gs_name->str;
-                       g_string_free(gs_name, FALSE);
+                       *name = g_string_free(gs_name, FALSE);
                }
        } else {
                g_string_free(gs_name, TRUE);
        }
 
-       *plugin = gs_plugin->str;
-       *comp_cls = gs_comp_cls->str;
-       g_string_free(gs_plugin, FALSE);
-       g_string_free(gs_comp_cls, FALSE);
+       *plugin = g_string_free(gs_plugin, FALSE);
+       *comp_cls = g_string_free(gs_comp_cls, FALSE);
        gs_name = NULL;
        gs_plugin = NULL;
        gs_comp_cls = NULL;
@@ -3088,10 +3085,8 @@ int split_timerange(const char *arg, char **begin, char **end)
 
        BT_ASSERT(begin);
        BT_ASSERT(end);
-       *begin = g_begin->str;
-       *end = g_end->str;
-       g_string_free(g_begin, FALSE);
-       g_string_free(g_end, FALSE);
+       *begin = g_string_free(g_begin, FALSE);
+       *end = g_string_free(g_end, FALSE);
        g_begin = NULL;
        g_end = NULL;
        goto end;
This page took 0.028875 seconds and 4 git commands to generate.