Skip to content

Commit b8f7f49

Browse files
walaclenticularis39
authored andcommitted
rtla: Use strdup() to simplify code
The actions_add_trace_output() and actions_add_shell() functions were using calloc() followed by strcpy() to allocate and copy a string. This can be simplified by using strdup(), which allocates memory and copies the string in a single step. Replace the calloc() and strcpy() calls with strdup(), making the code more concise and readable. Signed-off-by: Wander Lairson Costa <wander@redhat.com> Link: https://lore.kernel.org/r/20260309195040.1019085-3-wander@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent 009a8e6 commit b8f7f49

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

tools/tracing/rtla/src/actions.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ actions_add_trace_output(struct actions *self, const char *trace_output)
6969

7070
self->present[ACTION_TRACE_OUTPUT] = true;
7171
action->type = ACTION_TRACE_OUTPUT;
72-
action->trace_output = calloc_fatal(strlen(trace_output) + 1, sizeof(char));
73-
strcpy(action->trace_output, trace_output);
72+
action->trace_output = strdup_fatal(trace_output);
7473
}
7574

7675
/*
@@ -97,8 +96,7 @@ actions_add_shell(struct actions *self, const char *command)
9796

9897
self->present[ACTION_SHELL] = true;
9998
action->type = ACTION_SHELL;
100-
action->command = calloc_fatal(strlen(command) + 1, sizeof(char));
101-
strcpy(action->command, command);
99+
action->command = strdup_fatal(command);
102100
}
103101

104102
/*

0 commit comments

Comments
 (0)