[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251117184409.42831-3-wander@redhat.com>
Date: Mon, 17 Nov 2025 15:41:09 -0300
From: Wander Lairson Costa <wander@...hat.com>
To: Steven Rostedt <rostedt@...dmis.org>,
Wander Lairson Costa <wander@...hat.com>,
Tomas Glozar <tglozar@...hat.com>,
Ivan Pravdin <ipravdin.official@...il.com>,
Crystal Wood <crwood@...hat.com>,
John Kacur <jkacur@...hat.com>,
Costa Shulyupin <costa.shul@...hat.com>,
Tiezhu Yang <yangtiezhu@...ngson.cn>,
linux-trace-kernel@...r.kernel.org (open list:Real-time Linux Analysis (RTLA) tools),
linux-kernel@...r.kernel.org (open list),
bpf@...r.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_))
Subject: [rtla 02/13] 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@...hat.com>
---
tools/tracing/rtla/src/actions.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/actions.c
index 01648a1425c10..696dd1ed98d9a 100644
--- a/tools/tracing/rtla/src/actions.c
+++ b/tools/tracing/rtla/src/actions.c
@@ -78,10 +78,9 @@ actions_add_trace_output(struct actions *self, const char *trace_output)
self->present[ACTION_TRACE_OUTPUT] = true;
action->type = ACTION_TRACE_OUTPUT;
- action->trace_output = calloc(strlen(trace_output) + 1, sizeof(char));
+ action->trace_output = strdup(trace_output);
if (!action->trace_output)
return -1;
- strcpy(action->trace_output, trace_output);
return 0;
}
@@ -118,10 +117,9 @@ actions_add_shell(struct actions *self, const char *command)
self->present[ACTION_SHELL] = true;
action->type = ACTION_SHELL;
- action->command = calloc(strlen(command) + 1, sizeof(char));
+ action->command = strdup(command);
if (!action->command)
return -1;
- strcpy(action->command, command);
return 0;
}
--
2.51.1
Powered by blists - more mailing lists