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/51C2E204.1080501@huawei.com

Signed-off-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
This commit is contained in:
Zhao Hongjiang 2013-06-20 19:05:40 +08:00 committed by Steven Rostedt
parent 9674b2fada
commit d8fae2f644

View file

@ -87,7 +87,7 @@ TRACE_EVENT(foo_bar,
), ),
TP_fast_assign( TP_fast_assign(
strncpy(__entry->foo, foo, 10); strlcpy(__entry->foo, foo, 10);
__entry->bar = bar; __entry->bar = bar;
), ),