From: Jérémie Galarneau Date: Tue, 2 Nov 2021 19:35:27 +0000 (-0400) Subject: Clean-up: lttngctl: copy string using strdup instead of asprintf X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e32a3d0f431b41123e001abcbce329da6532f903;p=lttng-tools.git Clean-up: lttngctl: copy string using strdup instead of asprintf 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 --- 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,