From c3399cd46f7a33db516b5716a2ce0ebf50fd117a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 19 Dec 2023 14:47:24 +0100 Subject: [PATCH] lib: Avoid memcpy in debug_lttng_log() tracef() understands the %.*s format. Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- lib/util/debug.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/util/debug.c b/lib/util/debug.c index 0dd8e2e954b..4c10fde1b8e 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -402,16 +402,19 @@ static void debug_systemd_log(int msg_level, const char *msg, size_t msg_len) static void debug_lttng_log(int msg_level, const char *msg, size_t msg_len) { if (state.hs_len > 0) { - ensure_copy_no_nl(state.header_str_no_nl, - sizeof(state.header_str_no_nl), - state.header_str, - state.hs_len); - tracef(state.header_str_no_nl); + size_t len = state.hs_len; + + if (state.header_str[len - 1] == '\n') { + len -= 1; + } + + tracef("%.*s", (int)len, state.header_str); } - ensure_copy_no_nl(state.msg_no_nl, - sizeof(state.msg_no_nl), - msg, msg_len); - tracef(state.msg_no_nl); + + if ((msg_len > 0) && (msg[msg_len - 1] == '\n')) { + msg_len -= 1; + } + tracef("%.*s", (int)msg_len, msg); } #endif /* WITH_LTTNG_TRACEF */