Skip to content

Commit d8fae2f

Browse files
Zhao Hongjiangrostedt
Zhao Hongjiang
authored andcommitted
tracing: Change trace event sample to use strlcpy instead of strncpy
Strings should be copied with strlcpy instead of strncpy when they will later be printed via %s. This guarantees that they terminate with a NUL '\0' character and do not run pass the end of the allocated string. This is only for sample code, but it should stil represent a good role model. Link: http://lkml.kernel.org/p/[email protected] Signed-off-by: Zhao Hongjiang <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 9674b2f commit d8fae2f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

samples/trace_events/trace-events-sample.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TRACE_EVENT(foo_bar,
8787
),
8888

8989
TP_fast_assign(
90-
strncpy(__entry->foo, foo, 10);
90+
strlcpy(__entry->foo, foo, 10);
9191
__entry->bar = bar;
9292
),
9393

0 commit comments

Comments
 (0)