From: Simon Marchi Date: Mon, 3 Apr 2023 01:09:56 +0000 (-0400) Subject: cli: use return value of g_string_free X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=2e4a3da35892bf53e49936532a3a04e4c6819cb3 cli: use return value of g_string_free 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 Reviewed-by: Philippe Proulx --- diff --git a/src/cli/babeltrace2-cfg-cli-args.c b/src/cli/babeltrace2-cfg-cli-args.c index 6c187b4f..a0da0ddf 100644 --- a/src/cli/babeltrace2-cfg-cli-args.c +++ b/src/cli/babeltrace2-cfg-cli-args.c @@ -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;