From e32a3d0f431b41123e001abcbce329da6532f903 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 2 Nov 2021 15:35:27 -0400 Subject: [PATCH] Clean-up: lttngctl: copy string using strdup instead of asprintf MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use strdup to copy a string instead of using the formatting utilities. The code of the function is also adapted to follow the coding standards. Signed-off-by: Jérémie Galarneau Signed-off-by: Jérémie Galarneau Change-Id: I13328737e42a0287a7402761f75c67eef0dbdfdd --- src/lib/lttng-ctl/lttng-ctl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 887d268ef..83a884c17 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -2614,20 +2614,26 @@ end: */ int lttng_set_tracing_group(const char *name) { + int ret = 0; char *new_group; + if (name == NULL) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } - if (asprintf(&new_group, "%s", name) < 0) { - return -LTTNG_ERR_FATAL; + new_group = strdup(name); + if (!new_group) { + ret = -LTTNG_ERR_FATAL; + goto end; } free(tracing_group); tracing_group = new_group; new_group = NULL; - return 0; +end: + return ret; } int lttng_calibrate(struct lttng_handle *handle, -- 2.34.1