fs/xfs/./scrub/trace.h:748:3: warning: 'strncpy' specified bound 256 equals destination size

From: kernel test robot
Date: Thu Mar 28 2024 - 17:07:44 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 8d025e2092e29bfd13e56c78e22af25fac83c8ec
commit: 3934e8ebb7cc6e5f1ade35d586ed3eb79b88eb95 xfs: create a big array data structure
date: 8 months ago
config: x86_64-buildonly-randconfig-005-20240328 (https://download.01.org/0day-ci/archive/20240329/202403290419.HPcyvqZu-lkp@xxxxxxxxx/config)
compiler: gcc-8 (Ubuntu 8.4.0-3ubuntu2) 8.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240329/202403290419.HPcyvqZu-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202403290419.HPcyvqZu-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

In file included from include/trace/define_trace.h:103,
from fs/xfs/scrub/trace.h:1119,
from fs/xfs/scrub/trace.c:42:
fs/xfs/./scrub/trace.h: In function 'perf_trace_xfile_create':
>> fs/xfs/./scrub/trace.h:748:3: warning: 'strncpy' specified bound 256 equals destination size [-Wstringop-truncation]
strncpy(__entry->pathname, path, sizeof(__entry->pathname));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/trace/perf.h:51:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
{ assign; } \
^~~~~~
include/trace/trace_events.h:44:9: note: in expansion of macro 'PARAMS'
PARAMS(assign), \
^~~~~~
fs/xfs/./scrub/trace.h:731:1: note: in expansion of macro 'TRACE_EVENT'
TRACE_EVENT(xfile_create,
^~~~~~~~~~~
fs/xfs/./scrub/trace.h:739:2: note: in expansion of macro 'TP_fast_assign'
TP_fast_assign(
^~~~~~~~~~~~~~
In file included from include/trace/define_trace.h:102,
from fs/xfs/scrub/trace.h:1119,
from fs/xfs/scrub/trace.c:42:
fs/xfs/./scrub/trace.h: In function 'trace_event_raw_event_xfile_create':
>> fs/xfs/./scrub/trace.h:748:3: warning: 'strncpy' specified bound 256 equals destination size [-Wstringop-truncation]
strncpy(__entry->pathname, path, sizeof(__entry->pathname));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:402:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
{ assign; } \
^~~~~~
include/trace/trace_events.h:44:9: note: in expansion of macro 'PARAMS'
PARAMS(assign), \
^~~~~~
fs/xfs/./scrub/trace.h:731:1: note: in expansion of macro 'TRACE_EVENT'
TRACE_EVENT(xfile_create,
^~~~~~~~~~~
fs/xfs/./scrub/trace.h:739:2: note: in expansion of macro 'TP_fast_assign'
TP_fast_assign(
^~~~~~~~~~~~~~


vim +/strncpy +748 fs/xfs/./scrub/trace.h

730
731 TRACE_EVENT(xfile_create,
732 TP_PROTO(struct xfile *xf),
733 TP_ARGS(xf),
734 TP_STRUCT__entry(
735 __field(dev_t, dev)
736 __field(unsigned long, ino)
737 __array(char, pathname, 256)
738 ),
739 TP_fast_assign(
740 char pathname[257];
741 char *path;
742
743 __entry->ino = file_inode(xf->file)->i_ino;
744 memset(pathname, 0, sizeof(pathname));
745 path = file_path(xf->file, pathname, sizeof(pathname) - 1);
746 if (IS_ERR(path))
747 path = "(unknown)";
> 748 strncpy(__entry->pathname, path, sizeof(__entry->pathname));
749 ),
750 TP_printk("xfino 0x%lx path '%s'",
751 __entry->ino,
752 __entry->pathname)
753 );
754

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki