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 <jeremie.galarneau@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I13328737e42a0287a7402761f75c67eef0dbdfdd
*/
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,