Fix application of sizeof to pointer
PATCH 1/1 Fix application of sizeof to pointer
From: David Yang <[email protected]>
The coccinelle check report:
"./tools/tracing/latency/latency-collector.c:1541:10-16:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.
--- tools/tracing/latency/latency-collector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/tracing/latency/latency-collector.c +1 -1
@@ -1538,7 +1538,7 @@ static void tracing_loop(void)mutex_lock (&print_mtx);check_signals ();write_or_die (fd_stdout, queue_full_warning, -sizeof (queue_full_warning)); +strlen (queue_full_warning) +1 );mutex_unlock (&print_mtx); } modified--;
Signature · 1 line
2.30.2
Quoted 18 lines · On Tue, 12 Oct 2021 10:54:24 +0800 [email protected] wrote:
From: David Yang <[email protected]>
The coccinelle check report:
"./tools/tracing/latency/latency-collector.c:1541:10-16:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.Reported-by Zeal Robot <[email protected]>Signed-off-by David Yang <[email protected]>--- tools/tracing/latency/latency-collector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/tracing/latency/latency-collector.c +0
-0
tools/tracing/latency/latency-collector.c static void tracing_loop(void) · line 1541
Quoted 5 lines
tools/tracing/latency/latency-collector.c +1
-1@@ -1538,7 +1538,7 @@ static void tracing_loop(void)mutex_lock (&print_mtx);check_signals ();write_or_die (fd_stdout, queue_full_warning, -sizeof (queue_full_warning)); +strlen (queue_full_warning) +1 );
Really, the +1, although would match if queue_full_warning was an array, but in this use case, there's no reason to pass the nul character to the write.
-- Steve
Quoted 3 lines
tools/tracing/latency/latency-collector.c +0
-0mutex_unlock (&print_mtx); } modified--;
Quoted 16 lines · Steven Rostedt
Quoted 13 lines · On Tue, 12 Oct 2021 10:54:24 +0800 [email protected] wrote:
From: David Yang <[email protected]>
The coccinelle check report:
"./tools/tracing/latency/latency-collector.c:1541:10-16:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.Reported-by Zeal Robot <[email protected]>Signed-off-by David Yang <[email protected]>--- tools/tracing/latency/latency-collector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
tools/tracing/latency/latency-collector.c static void tracing_loop(void) · line 1541
Quoted 11 lines
tools/tracing/latency/latency-collector.c +1
-1@@ -1538,7 +1538,7 @@ static void tracing_loop(void)mutex_lock (&print_mtx);check_signals ();write_or_die (fd_stdout, queue_full_warning, -sizeof (queue_full_warning)); +strlen (queue_full_warning) +1 );Really, the +1, although would match if
queue_full_warningwas an array, but in this use case, there's no reason to pass the nul character to the write.
I agree that the +1 should not be there because the null character would end up in the output; write will not ignore it. It could be confusing if the output would be be processed by another program.
best regards,
Viktor
Quoted 7 lines
-- Steve
Quoted 3 lines
tools/tracing/latency/latency-collector.c +0
-0mutex_unlock (&print_mtx); } modified--;