tracing: Change trace event sample to use strlcpy instead of strncpy
authorZhao Hongjiang <zhaohongjiang@huawei.com>
Thu, 20 Jun 2013 11:05:40 +0000 (19:05 +0800)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 1 Jul 2014 11:13:33 +0000 (07:13 -0400)
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>
samples/trace_events/trace-events-sample.h

index 4b0113f73ee9a11b1f50aee09f9a56964f01a3c4..476429281389e03d7744bf0aa9deabefa336b58b 100644 (file)
@@ -87,7 +87,7 @@ TRACE_EVENT(foo_bar,
        ),
 
        TP_fast_assign(
-               strncpy(__entry->foo, foo, 10);
+               strlcpy(__entry->foo, foo, 10);
                __entry->bar    = bar;
        ),